我们有一个名称/值对表,其中仅包含可以与属性site_id,netpark_location_id等相关联的其他项。
cakephp返回PropertyOption表的hasMany关联时,其格式为hasMany关联的正常格式:
[PropertyOption] => Array
(
[0] => Array
(
[id] => 1
[property_id] => 1
[name] => prs_company_id
[value] => 7
[type] => text
[created] => 2018-10-02 16:05:38
[modified] => 2018-10-02 16:05:38
)
[1] => Array
(
[id] => 1
[property_id] => 1
[name] => prs_channel_id
[value] => 880
[type] => text
[created] => 2018-10-02 16:05:38
[modified] => 2018-10-02 16:05:38
)
是否存在将数据按摩到
的行为或afterFind方法 [PropertyOption] => Array
(
[prs_channel_id] => 880
[prs_company_id] => 7
)
当前,我在AppModel中使用了一个函数,该函数允许我将结果集传递给它,但这是一个额外的调用
public function nameValPair($alias,$results){
$result = [];
if(is_array($results[$alias]) && count($results[$alias]) > 0){
foreach ($results[$alias] AS $r){
$result[$r['name']] = $r['value'];
}
}
return $result;
}
然后在Controller中,我们必须在
中传递结果$propoption = $this->Property->nameValPair('PropertyOption',$property);
$property['PropertyOption'] = $propoption;