I have a Doctrine query in my model say Model_1Table.class.php that left joins with Model_2. Model_2 relates to Model_1 on a many-to-one relation. (it really is a one-to-one relation and not a many-to-one but the schema got designed so)
My query is:
$this->select('m1.*, m2.primaryKeyOfModel2')->leftJoin('m1.model2 m2')->where('m1.record = ?', some_value);
Inspecting SF Debugger logs, it retrieves the information as it should, retaining all table records from Model_1 that satisfy the where clause and retaining all values of Model_2 along with null values for those that do not exist.
The pain begins when I want to access this information, and conditionally render information dependent upon the presence/absence of model_2 records in my table. which I do like this:
<?php foreach($Model1Records as $Model1Record) :
if($Model1Record->getModel2()) :
foreach($Model1Record->getModel2() as $Model2Record):
//do something
end foreach ;
else: //basically checking for if(!($Model1Record->getModel2()))
// do something else
endif;
endforeach ; ?>
Now based on this it should really work, but I think what is happening is that for the null values of model2 it fails. how do I infer that, well because if I remove the if-else statements in the above record and simply access the collection of Model2Record with a foreach loop, the available rows in Model2Record are retrieved, but then offcourse it does not access the null values. Essentially, the information I get from this is what I would typically get from an inner join.
To frame a question, how do I access records of the Model1 that have Model2 records as null values ?