OnlyID is like Only, but returns the only Meta ID in the query. Returns a *NotSingularError when more than one Meta ID is found. Returns a *NotFoundError when no entities are found.
(ctx context.Context)
| 158 | // Returns a *NotSingularError when more than one Meta ID is found. |
| 159 | // Returns a *NotFoundError when no entities are found. |
| 160 | func (_q *MetaQuery) OnlyID(ctx context.Context) (id int, err error) { |
| 161 | var ids []int |
| 162 | if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { |
| 163 | return |
| 164 | } |
| 165 | switch len(ids) { |
| 166 | case 1: |
| 167 | id = ids[0] |
| 168 | case 0: |
| 169 | err = &NotFoundError{meta.Label} |
| 170 | default: |
| 171 | err = &NotSingularError{meta.Label} |
| 172 | } |
| 173 | return |
| 174 | } |
| 175 | |
| 176 | // OnlyIDX is like OnlyID, but panics if an error occurs. |
| 177 | func (_q *MetaQuery) OnlyIDX(ctx context.Context) int { |
no test coverage detected