Only returns a single Workflow entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one Workflow entity is found. Returns a *NotFoundError when no Workflow entities are found.
(ctx context.Context)
| 303 | // Returns a *NotSingularError when more than one Workflow entity is found. |
| 304 | // Returns a *NotFoundError when no Workflow entities are found. |
| 305 | func (_q *WorkflowQuery) Only(ctx context.Context) (*Workflow, error) { |
| 306 | nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) |
| 307 | if err != nil { |
| 308 | return nil, err |
| 309 | } |
| 310 | switch len(nodes) { |
| 311 | case 1: |
| 312 | return nodes[0], nil |
| 313 | case 0: |
| 314 | return nil, &NotFoundError{workflow.Label} |
| 315 | default: |
| 316 | return nil, &NotSingularError{workflow.Label} |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | // OnlyX is like Only, but panics if an error occurs. |
| 321 | func (_q *WorkflowQuery) OnlyX(ctx context.Context) *Workflow { |
no test coverage detected