タイトルが私が目指しているものを逃した場合は申し訳ありませんが、これに名前を付ける方法がわかりませんでした. これが私のクエストです:
価格 (1:1) に属する複数のアイテム (1:n) を保持する単一のカートがあります。
アイテムと価格の間の関係も同様に機能しています。
class Item extends AppModel {
public $hasOne = 'Price';
}
class Price extends AppModel {
public $belongsTo = array(
'Item' => array(
'className' => 'Item',
'foreignKey' => 'id'
)
);
}
しかし今、私はカートの選択 (検索) を行い、それらのアイテムを含めたいと思っています。これも同様に機能しています:
class CartItem extends AppModel {
public $useTable = 'cart_items';
public $belongsTo = array('Item', 'Address');
}
しかし、私が本当に必要としているのは、機能していない各アイテムの価格を取得することです (Item-Model の afterFind()-Callback の $result には割り当てられた価格が含まれず、Price-Model の afterFind()-Callback は呼び出されません)カートを見つけるとき)。
ここで何が欠けていますか?
/編集: 最近の変更:
class AppModel extends Model {
var $actsAs = array('Containable');
}
class CartsController extends AppController {
public function getCart() {
$cart = ClassRegistry::init('CartItem')->find('all', array(
'contain' => array(
'Item' => array(
'Price'
),
'Address'
),
'conditions' => array(
'id_cart' => $cart['Cart']['id']
)
));
}
上記の変更により、見つかった項目に Price が取得されますが、最後に見つかった項目にのみ取得されます。