OnlyID is like Only, but returns the only User ID in the query. Returns a *NotSingularError when more than one User ID is found. Returns a *NotFoundError when no entities are found.
(ctx context.Context)
| 186 | // Returns a *NotSingularError when more than one User ID is found. |
| 187 | // Returns a *NotFoundError when no entities are found. |
| 188 | func (_q *UserQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { |
| 189 | var ids []uuid.UUID |
| 190 | if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { |
| 191 | return |
| 192 | } |
| 193 | switch len(ids) { |
| 194 | case 1: |
| 195 | id = ids[0] |
| 196 | case 0: |
| 197 | err = &NotFoundError{user.Label} |
| 198 | default: |
| 199 | err = &NotSingularError{user.Label} |
| 200 | } |
| 201 | return |
| 202 | } |
| 203 | |
| 204 | // OnlyIDX is like OnlyID, but panics if an error occurs. |
| 205 | func (_q *UserQuery) OnlyIDX(ctx context.Context) uuid.UUID { |
no test coverage detected