Relational Query ->with() Condition, with Zero Related Entries

Hi all,

Consider the following query:

Model::model()->with(array(‘notes’ => array(‘condition’ => ‘is_deleted=0’)))->findByPk(57);

If the model with the ID of 57 has notes associated with it that are deleted, this query will rightly omit those notes from the result. Likewise, if it has notes but none are deleted, it simply returns all the notes. BUT, if if it has NO notes associated with it, the result will be empty, even though the model with that ID definitely exists.

Now, I do know, functionally, why it’s working this way: if there is are no ‘notes’ associated with this ID at all, then the condition cannot be evaluated. My question is not so much ‘why isn’t this working’, as ‘how can I construct a query that will do what I want’?

I want to get the model with the ID of, say, 57. I want to get all notes associated with that model, UNLESS the note’s is_deleted column is equal to 0, in which case I want to skip it. BUT I still want to get the model if it has no notes at all.

How do I accomplish this?

Anyone?

I think that you have to specify "together=false" or make sure that you do not have "inner join" when you use this call.