これが、データ マッパー パターンの使用を支持する議論の核心です。例で使用しているように見える構造では、オブジェクトをモデルに
渡そうとすると大きな問題が発生します。ただし、クエリで結合を実行してテーブルに結合することはできますが、オブジェクトでの結合は合理的ではありません。organisation_types
Organisation
organisation_types
organization_types テーブルに参加するには:
//assuming this is a DbTable model that extends Zend_Db_Table_Abstract
function getOrganisations($where=null,$order='name ASC',$offset=null,$limit=null){
$select = $this->select()->setIntegrityCheck(FALSE);//This locks the table to allow joins
$select->joinLeft('organisation_types', 'organisation_types.id = organisation.organisation_type_id');//This will join the tables with all feilds, use the join type you like.
if (!is_null($where) {
$select->where($where);
}
if (!is_null($order) {
$select->order($order);
}
if (!is_null($offset) {
$select->limit(null,$offset);//offset is second arg in limit() in select()
}
if (!is_null($limit) {
$select->limit($limit);
}
$Result = $this->fetchAll($select);
if (!$Result){
return array();
}
return $Result->toArray();
}
これにより、テーブル結合がどのように機能するかがわかります。オブジェクトを使用したい場合は、別の構造でやり直す必要があります。
PHPMaster で、データ マッパーとドメイン モデルを理解するのに役立ついくつかの優れたチュートリアルを見つけました。
ドメイン モデルの構築、はじめに
データ マッパーの統合
また、オンライン ブックのSurvive The Deependには、データ マッパー パターンとそのテスト方法の良い例があります。
幸運を...