1
我對cakephp相當陌生,我在模型上遇到複雜的find
函數問題。在複雜的cakephp模型中排除條件的問題
我有一個Groups
的數字,每個數字包含Users
,每個組可以編號爲Orders
。每個訂單由若干OrderAmounts
組成,其中包含amount
和user_id
(與用戶有關)。
我有一個發現它找到一個訂單,並返回本集團與該訂單的所有用戶和對應於用戶的任何OrderAmounts:
$currentOrder = $this->Order->find('first', array(
'conditions' => array(
'Order.group_id' => $this->Session->read("Auth.User.group_id")
),
'contain' => array(
'Group' => array(
'User' => array(
'OrderAmount' => array(
'OrderAmountType'
)
)
)
)
));
我現在想要做的是返回一個列表所有與上述訂單相關的用戶沒有相應的OrderAmount。
到目前爲止,我有這個,但我不知道放在哪裏,排除用戶OrderAmounts條件 - 如果我把條件中包含部分它只是刪除從模型中OrderAmounts,如果我把它們在查找的頂級條件中,我得到一個錯誤。
$currentOrderOutstanding = $this->Order->Group->User->find('all', array(
'conditions' => array(
'Group.id' => $this->Session->read("Auth.User.group_id")
),
'fields' => array('User.id'),
'contain' => array(
'OrderAmount',
'Group'
)
));
這似乎並沒有爲我添加條件標記(或在我的原始示例OrderAmount) - 添加一個條件OrderAmount只是返回一個空數組OrderAmounts它不符合條件 - 它沒有對用戶返回的影響 - 這似乎違背了手冊中的說明,但我看不出爲什麼 – Loftx 2010-05-14 13:04:44