I have a "user" model which have a has_many relation with a "unavailable" model containing periods of unavailability. So I added condition on the relation with an ORM query like this :
Model_User::query()
->related(array(
'collaborator',
'schedule',
'unavailable' => array(
'where' => array(
array('time_start', '<', time()),
array('time_end', '>', time())
)
)
))
->where('is_collaborator', '=', true)
->get();
The problem is that its only fetch the users who do have a unavailable relation matching the where. I looked the query and its perfectly normal since the relation's where is in the main query and not in a subquery. There are solutions with plain SQL like using the ON clause instead of where, or use a "t3.myfield IS NULL OR WHERE(my conditions)".
But since the relation conditions feature is quite strict with syntax, I dont know how to do it.
WHERE's defined on the relation should become part of the ON clause, and not generate a WHERE clause.
I know that works fine on conditions defined in the relation definition in the model, which is what I always use. I have to dive into the code to see if your syntax is supported, or why that creates a different result.
Yeah, I wanted to put it in the relation definition but if I do so, the time() in the arrays trigger a parsing error " syntax error, unexpected '(', expecting ')' "
Great, I wasnt aware of this method. But despite my tries I can't figure out how to do it, I get errors everytime. Can you give me a small piece of example about relation definition ?