Php Zend框架leftJoin
这是不起作用的代码Php Zend框架leftJoin,php,zend-framework,left-join,Php,Zend Framework,Left Join,这是不起作用的代码 $select = $tariffsTable->select(Zend_Db_Table_Abstract::SELECT_WITHOUT_FROM_PART) ->from('tariff', null) ->where('id = ?', $this->id) ->joinLeft('characteri
$select = $tariffsTable->select(Zend_Db_Table_Abstract::SELECT_WITHOUT_FROM_PART)
->from('tariff', null)
->where('id = ?', $this->id)
->joinLeft('characteristic_value',
'characteristic_value.tariff_id = id',
array('value_' . $locale, 'characteristic_id'))
->joinLeft('characteristic',
'id = characteristic_value.characteristic_id',
array('name_' . $locale, 'alias'));
$select->setIntegrityCheck(false);
$tariffCharacteristics = $tariffsTable->fetchAll($select)->toArray();
谢谢你的帮助!我已经解决了这个问题。以下是工作代码:
$select = $tariffsTable->select(Zend_Db_Table_Abstract::SELECT_WITHOUT_FROM_PART)
->from('tariff', null)
->joinLeft( array('characteristic_value'),
'characteristic_value.tariff_id = tariff.id',
array('value_' . $locale))
->joinLeft(array('characteristic'),
'characteristic.id = characteristic_value.characteristic_id',
array('name_' . $locale, 'alias'))
->where('tariff.id = ?', $this->id);
$select->setIntegrityCheck(false);
这是因为您正在使用
WHERE
和/或LEFT JOIN on
子句上的id
列,而您尝试加入的两个表中都应该存在id列
您需要指定在这两种情况下都应使用哪个id
例如characteristic.id或characteristic_value.id或tarriff.id
通过将数组用作from()
和joinLeft()
方法的参数,可以使用别名
$select->from(array('t' => 'tarriff'))
->where('t.id = ?', $this->id);