I think you do not need to propagate standard Doctrine behavior unless you want this to be fully automatic. But still, you can try to do this, just like we do - we use a DAO (data access object) that returns a specific Doctrine object (a view of the Doctrine table):
\DAO::get('Some\Namespace\Classname')
where Classname stands for the table described by the PHP class model. Our DAO class creates an instance of Classname , which is enclosed in a proxy (see "Design Patterns").
Outside of the table class model, we create another class for this table, which stands above the table model and manipulates this model. In this class, we write methods such as getProducts($args) , getProduct($id) , getProductsByCategory($catId) , etc.
I think this is what you are looking for ...
In the getProducts($args) method, then you can implement ->leftJoin() inside the DQL, which will join the translation table by specifying the $lang identifier in the $args parameter. Simple example (not verified):
class Products extends \DAO { public function save($item) { $item->save(); } public function getProducts($args = array()) { $order = array('p.id'); $result = \Doctrine_Query::create() ->from('Some\Namespace\Product p') ->where('1 = 1'); if(!empty($args['lang'])) { $result = $result->leftJoin('Some\Namespace\ProductTranslation pt ON pt.product_id = p.id AND pt.language = ?', $args['lang']); } $result = $result->orderBy($order); $result = $result->execute(); return $result; } }
Then calling
$products = DAO::get('Some\Namespace\Product')->getProducts(array('lang' => 1));
You get all products with English translations uploaded ...
It is not so automated, and you have to write your own DAO class for each model, but this is a good approach, since you have a different data definition class (model) and a data management class (controller) needed for an MVC / MVP object-oriented application architecture ...
shadyyx
source share