Orm 连接和或结束于和的位置
我有以下代码:Orm 连接和或结束于和的位置,orm,cakephp-3.0,Orm,Cakephp 3.0,我有以下代码: $_duplicates = $this->find() ->innerJoin( ['c' => 'contacts'], //alias [ 'Contacts.contactname != ' => '', 'Contacts.id < c.id', 'c.id > ' => 0 ]
$_duplicates = $this->find()
->innerJoin(
['c' => 'contacts'], //alias
[
'Contacts.contactname != ' => '',
'Contacts.id < c.id',
'c.id > ' => 0
]
)
->select(['Contacts.id', 'Contacts.contactname', 'Contacts.legalname',
'c.id', 'c.contactname', 'c.legalname'])
->orWhere([
'LEVENSHTEIN(Contacts.contactname, c.contactname) <= ' => $distance,
'LEVENSHTEIN(Contacts.contactname, c.legalname) <= ' => $distance,
'LEVENSHTEIN(Contacts.legalname, c.contactname) <= ' => $distance,
'LEVENSHTEIN(Contacts.legalname, c.legalname) <= ' => $distance
]);
debug($_duplicates);
$\u duplicates=$this->find()
->内部连接(
['c'=>'contacts'],//别名
[
'Contacts.contactname!='=>'',
“Contacts.id”=>0
]
)
->选择(['Contacts.id'、'Contacts.contactname'、'Contacts.legalname',
“c.id”、“c.contactname”、“c.legalname”])
->或者在哪里([
'LEVENSHTEIN(Contacts.contactname,c.contactname)因为或where()
不是这样工作的,所以或
条件用于与先前通过where/andWhere/orWhere()定义的条件组合,即
->where(['a' => 'b'])
->orWhere(['c' => 'd', 'e' => 'f'])
导致
(c = d AND e = f) OR a = b
如果需要通过或
组合所有条件,则可以使用多个或where()
调用
->orWhere(['a' => 'b'])
->orWhere(['c' => 'd'])
->orWhere(['e' => 'f'])
或
键
->where([
'OR' => [
'a' => 'b'
'c' => 'd'
'e' => 'f'
]
])
或表达
->where(function (\Cake\Database\Expression\QueryExpression $exp) {
return
$exp->or_([
'a' => 'b'
'c' => 'd'
'e' => 'f'
]);
})
另请参见
->where(function (\Cake\Database\Expression\QueryExpression $exp) {
return
$exp->or_([
'a' => 'b'
'c' => 'd'
'e' => 'f'
]);
})