Only returns a single Meta entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one Meta entity is found. Returns a *NotFoundError when no Meta entities are found.
(ctx context.Context)
| 131 | // Returns a *NotSingularError when more than one Meta entity is found. |
| 132 | // Returns a *NotFoundError when no Meta entities are found. |
| 133 | func (_q *MetaQuery) Only(ctx context.Context) (*Meta, error) { |
| 134 | nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) |
| 135 | if err != nil { |
| 136 | return nil, err |
| 137 | } |
| 138 | switch len(nodes) { |
| 139 | case 1: |
| 140 | return nodes[0], nil |
| 141 | case 0: |
| 142 | return nil, &NotFoundError{meta.Label} |
| 143 | default: |
| 144 | return nil, &NotSingularError{meta.Label} |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // OnlyX is like Only, but panics if an error occurs. |
| 149 | func (_q *MetaQuery) OnlyX(ctx context.Context) *Meta { |