Only returns a single Group entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one Group entity is found. Returns a *NotFoundError when no Group entities are found.
(ctx context.Context)
| 159 | // Returns a *NotSingularError when more than one Group entity is found. |
| 160 | // Returns a *NotFoundError when no Group entities are found. |
| 161 | func (_q *GroupQuery) Only(ctx context.Context) (*Group, error) { |
| 162 | nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) |
| 163 | if err != nil { |
| 164 | return nil, err |
| 165 | } |
| 166 | switch len(nodes) { |
| 167 | case 1: |
| 168 | return nodes[0], nil |
| 169 | case 0: |
| 170 | return nil, &NotFoundError{group.Label} |
| 171 | default: |
| 172 | return nil, &NotSingularError{group.Label} |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | // OnlyX is like Only, but panics if an error occurs. |
| 177 | func (_q *GroupQuery) OnlyX(ctx context.Context) *Group { |
no test coverage detected