Only returns a single Setting entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one Setting entity is found. Returns a *NotFoundError when no Setting entities are found.
(ctx context.Context)
| 106 | // Returns a *NotSingularError when more than one Setting entity is found. |
| 107 | // Returns a *NotFoundError when no Setting entities are found. |
| 108 | func (sq *SettingQuery) Only(ctx context.Context) (*Setting, error) { |
| 109 | nodes, err := sq.Limit(2).All(setContextOp(ctx, sq.ctx, "Only")) |
| 110 | if err != nil { |
| 111 | return nil, err |
| 112 | } |
| 113 | switch len(nodes) { |
| 114 | case 1: |
| 115 | return nodes[0], nil |
| 116 | case 0: |
| 117 | return nil, &NotFoundError{setting.Label} |
| 118 | default: |
| 119 | return nil, &NotSingularError{setting.Label} |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // OnlyX is like Only, but panics if an error occurs. |
| 124 | func (sq *SettingQuery) OnlyX(ctx context.Context) *Setting { |
no test coverage detected