问题描述:

My table is using a Translation module

// This works fine for 1 item

$o = Doctrine_Core::getTable('myTable')->find(1);

echo $o->getName();

I want to be able to run a query and get all the rows with the name (which is in the translation table) correctly

$o = Doctring_Core::getTable('myTable').createQuery('a')

->leftJoin('a.Translation t')

->andWhere('a.visible = ?', true)

->andWhere('t.lang = ?', 'en')

->execute();

I want to be able to do

foreach($o as $item) {

echo $item->getName();

}

But my getName() is always null...

网友答案:

You need to use $item->Translation->name, or alternatively you can create a similar proxy function:

//lib/model/doctrine/myTable.class.php
function getName() {
  return $this->Translation->name;
}

This function can be called explicitly like $item->getName(), or implicitly via __get() as $item->name;

I'm guessing you're using doctrine's behavior for storing translations - never used it, so your mileage may vary.

相关阅读:
Top