我在这里问一个与 CakePhp 引擎有关的问题。 当我问自己时,我只是编码:
我有一个Customer
模型,其中有多个地址,但有2个别名(一个用于Address.type = "l"
,另一个用于Address.type = "f"
)
一切正常,但我想假设我想做一个特殊的查询,它可以获取所有客户数据和两个相关地址,并为每个别名提供过滤器。
我该怎么办?
因为当我进行查询时,它就像第一个条件(别名中的那个条件)被丢弃,唯一有效的是最后一条。
Customer
型号
public $hasMany = array(
'AddressB' => array(
'className' => 'Address',
'foreignKey' => 'customer_id',
'dependent' => true,
'conditions' => array("AddressB.type" => "f"),
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'AddressD' => array(
'className' => 'Address',
'foreignKey' => 'customer_id',
'dependent' => true,
'conditions' => array("AddressD.type" => "l"),
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
然后我的查询:(也在客户模型中)
$d = $this->find("all", array(
"conditions" => array(
"id" => $customer_id
),
"contain" => array(
"AddressD" => array(
"conditions" => array("active" => true),
"Cp"
),
"AddressB" => array(
"conditions" => array("active" => true),
"Cp"
)
)
)
);