OnlyID is like Only, but returns the only Setting ID in the query. Returns a *NotSingularError when more than one Setting ID is found. Returns a *NotFoundError when no entities are found.
(ctx context.Context)
| 133 | // Returns a *NotSingularError when more than one Setting ID is found. |
| 134 | // Returns a *NotFoundError when no entities are found. |
| 135 | func (sq *SettingQuery) OnlyID(ctx context.Context) (id int, err error) { |
| 136 | var ids []int |
| 137 | if ids, err = sq.Limit(2).IDs(setContextOp(ctx, sq.ctx, "OnlyID")); err != nil { |
| 138 | return |
| 139 | } |
| 140 | switch len(ids) { |
| 141 | case 1: |
| 142 | id = ids[0] |
| 143 | case 0: |
| 144 | err = &NotFoundError{setting.Label} |
| 145 | default: |
| 146 | err = &NotSingularError{setting.Label} |
| 147 | } |
| 148 | return |
| 149 | } |
| 150 | |
| 151 | // OnlyIDX is like OnlyID, but panics if an error occurs. |
| 152 | func (sq *SettingQuery) OnlyIDX(ctx context.Context) int { |
no test coverage detected