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