Only returns a single Referrer entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one Referrer entity is found. Returns a *NotFoundError when no Referrer entities are found.
(ctx context.Context)
| 181 | // Returns a *NotSingularError when more than one Referrer entity is found. |
| 182 | // Returns a *NotFoundError when no Referrer entities are found. |
| 183 | func (_q *ReferrerQuery) Only(ctx context.Context) (*Referrer, error) { |
| 184 | nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) |
| 185 | if err != nil { |
| 186 | return nil, err |
| 187 | } |
| 188 | switch len(nodes) { |
| 189 | case 1: |
| 190 | return nodes[0], nil |
| 191 | case 0: |
| 192 | return nil, &NotFoundError{referrer.Label} |
| 193 | default: |
| 194 | return nil, &NotSingularError{referrer.Label} |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | // OnlyX is like Only, but panics if an error occurs. |
| 199 | func (_q *ReferrerQuery) OnlyX(ctx context.Context) *Referrer { |
no test coverage detected