jeudi 24 septembre 2015

Laravel/Eloquent: querying a belongsTo / hasMany relation

I have 2 tables : tasks and executions. A task "hasMany" executions (and an execution "belongsTo" a task).

Fields in table tasks: id (primary key), name, data, created_at, ...
Fields in table executions: id (primary key), process_name, created_at, task_id.

I want to get the oldest task (based on tasks.created_at) which,
- has never been been executed (no record in table executions with the task id as task_id),
OR
- has been executed by any other process but "MyProcess" => executions.process_name <> 'MyProcess'

I read the Eloquent doc and find the "Querying Relationship Existence" but I can't find how to query non-existence.

How can I do (I hope I was clear enough)? Thank you very much in advance, I'm stuck!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire