I’ve got below function in my Organisation model.
public function getOrganisations($where=null,$order='name ASC',$offset=null,$limit=null){
$Result = $this->fetchAll($where,$order,$limit,$offset);
if (!$Result){
return array();
}
return $Result->toArray();
}
but How can I include my organisation_types model so I can left join to organisation_type_id in organisation table?
This is the core of the argument in favor of using the data mapper pattern.
With the structure you seem to be using in your example you’ll have huge trouble trying pass the
organisation_typesobject into yourOrganisationmodel. You can however do a join in your query to join to theorganisation_typestable, but joining on the object is not likely to be reasonable.to join on the organisation_types table:
This should give you an idea of how a table join would work. If you want to use the objects you’ll need to begin again with a different structure.
I found a couple of good tutorials on PHPMaster that helped me get my head around the data mappers and domain models.
Building A Domain Model, Introduction
Integrating data mappers
Also The online book Survive The Deepend has a good example of the data mapper pattern and how to test it.
Good Luck…