Zend 框架 leftJoin
这是不起作用的代码。
$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);
Here is the code that doesn't work.
$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();
Thank you for help! I have solved the problem. Here is working code:
$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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为您在
WHERE
和/或LEFT JOIN ON
子句上使用id
列,而 id 列应该出现在您的两个表中尝试加入。您需要指定在这两种情况下应使用哪个 id。
例如characteristic.id或characteristic_value.id或tarriff.id。
您可以通过使用数组作为
from()
和joinLeft()
方法的参数来使用别名。It is because your are using
id
column onWHERE
and/orLEFT JOIN ON
clause while an id column should be present in both table your are trying to join.You need to specify which id should be used in both case.
Like characteristic.id or characteristic_value.id or tarriff.id.
You can use alias by using array as a parameter for
from()
andjoinLeft()
methods.