我正在使用 CakePHP 2.4。
我在数据库中有两个表,table1.num
和 **table2.num
,我需要通过连接查询将它们关联起来。
table1.num
有前缀 DA
,比如 DA-12929
,table2.num
有前缀 DB
,如 DB-12929
。
在我的应用中,我有一个连接
option = array(
'recursive' => -1,
'fields' => array('Table1.*', 'Table2.*'),
'joins' => array(
array('table' => 'table2',
'alias' => 'Table2',
'type' => 'INNER',
'conditions' => array(
'Tabe1.num = Table2.num',
),
),
),
);
我如何在没有前缀的情况下将它们联系起来?
最佳答案
嗨,我找到了一个解决方案,我只是添加了 SUBSTRING
option = array(
'recursive' => -1,
'fields' => array('Table1.*', 'Table2.*'),
'joins' => array(
array('table' => 'table2',
'alias' => 'Table2',
'type' => 'INNER',
'conditions' => array(
'SUBSTRING(Tabe1.num,4) = SUBSTRING(Table2.num,4)',
),
),
),
);
关于php - 关联两个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45741343/