在我的应用程序中,我有两个关联模型
通知 belongsTo
配置文件
这是我的通知模式
class Notification extends AppModel {
public $name = 'Notification';
public $belongsTo = array('Profile');
public function getnotification($id = NULL){
$result = $this->find('all',array(
'conditions' => array(
'Notification.receiver_id' => $id
)
));
return $result;
}
}
输出
Array
(
[0] => Array
(
[Notification] => Array
(
[id] => 1
[profile_id] => 8
[receiver_id] => 1
[notification_text] => tester Sent you message on project Test
[notification_descriptions] => {"projectid":"2"}
[is_active] => 1
[created_on] => 2014-08-29 18:50:38
[modified_on] => 2014-08-29 18:50:38
)
[Profile] => Array
(
[id] => 8
[user_id] => 8
[u_id] => 63c0cd43
[profile_firstname] => tester
[profile_lastname] => seller
[profile_gender] => 1
[profile_dob] => 1999-08-13
[profile_paypalid] => testseller2@yopmail.com
[profile_company] =>
[profile_occupation] => Web Developer
[profile_address] =>
[profile_city] =>
[profile_state] =>
[country_id] => 106
[profile_postalcode] =>
[currency_id] => 150
[timezone_id] => 93
[profile_avatar] =>
[profile_role] => 2
[profile_status] => 1
[about_me] => "But I must explain to you how all this mistaken idea"
[profile_title] =>
[rate_per_hour] =>
[language_id] => 38
[visibility] =>
[profile_rating] => 100
[is_active] => 1
[last_modified] => 2014-08-27 11:34:56
[rating] => 100
)
)
)
但它总是从表中返回第一行,即使有两行或更多行
预期产出
Array
(
[0] => Array
(
[Notification] => Array
(
[id] => 1
[profile_id] => 8
[receiver_id] => 1
[notification_text] => tester Sent you message on project Test
[notification_descriptions] => {"projectid":"2"}
[is_active] => 1
[created_on] => 2014-08-29 18:50:38
[modified_on] => 2014-08-29 18:50:38
)
[Profile] => Array
(
[id] => 8
[user_id] => 8
[u_id] => 63c0cd43
[profile_firstname] => tester
[profile_lastname] => seller
[profile_gender] => 1
[profile_dob] => 1999-08-13
[profile_paypalid] => testseller2@yopmail.com
[profile_company] =>
[profile_occupation] => Web Developer
[profile_address] =>
[profile_city] =>
[profile_state] =>
[country_id] => 106
[profile_postalcode] =>
[currency_id] => 150
[timezone_id] => 93
[profile_avatar] =>
[profile_role] => 2
[profile_status] => 1
[about_me] => "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was"
[profile_title] =>
[rate_per_hour] =>
[language_id] => 38
[visibility] =>
[profile_rating] => 100
[is_active] => 1
[last_modified] => 2014-08-27 11:34:56
[rating] => 100
)
)
[1] => Array
(
[Notification] => Array
(
[id] => 2
[profile_id] => 7
[receiver_id] => 1
[notification_text] => tester Sent you message on project Test
[notification_descriptions] => {"projectid":"2"}
[is_active] => 1
[created_on] => 2014-08-29 18:50:38
[modified_on] => 2014-08-29 18:50:38
)
[Profile] => Array
(
[id] => 7
[user_id] => 7
[u_id] => 63c0cd458
[profile_firstname] => teste
[profile_lastname] => person
[profile_gender] => 1
[profile_dob] => 1999-08-13
[profile_paypalid] => testseller2@yopmail.com
[profile_company] =>
[profile_occupation] => Web Developer
[profile_address] =>
[profile_city] =>
[profile_state] =>
[country_id] => 106
[profile_postalcode] =>
[currency_id] => 150
[timezone_id] => 93
[profile_avatar] =>
[profile_role] => 2
[profile_status] => 1
[about_me] => "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a c
[profile_title] =>
[rate_per_hour] =>
[language_id] => 38
[visibility] =>
[profile_rating] => 100
[is_active] => 1
[last_modified] => 2014-08-27 11:34:56
[rating] => 100
)
)
)
虽然$this->element('sql_dump');
显示 3 行由于查询而受到影响,但是当我打印结果时,它只显示一个结果,甚至count
& sizeof
show 1
。
考虑profile_id
为sender_id
谁能告诉我我在哪里做错了什么?