2011-07-16 1 views
0

cakePHP 1.3の多くのアソシエーションを持つモデルでfind( 'all' ...)を取得しようとします。スキーマ内の再帰の第2レベル。単純に、それはこのようになりますし、私はユーザーIDをフィルタリングしたい:ここcakePHP - 2回目の再帰でbelongsToを介してcantプルモデルアソシエート

Delivery belongsTo Order, Order belongsTo User. 

はassocsです:

Order: var $belongsTo = array(

'User' => array(
     'className' => 'User', 
     'foreignKey' => 'user_id', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '' 
),.... 

Delivery: var $belongsTo = array(

'Order' => array(
     'className' => 'Order', 
     'foreignKey' => 'order_id', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '' 
    ),... 

生じる誤差がある:ここでは

SQL Error: 1054: Unknown column 'User.id' in 'where clause' [CORE/cake/libs/model/datasources/dbo_source.php, line 684]

フルクエリちょうど楽しみのために:

SELECT Delivery . id , Delivery . order_id , Delivery . delivery_address_id , Delivery . deliver_date , Delivery . created , Delivery . modified , Delivery . deliver_run , Delivery . product_mix_id1 , Delivery . product_mix_id2 , Delivery . product_mix_id3 , Delivery . product_mix_id4 , Delivery . assembled , Delivery . shipped , Delivery . rated , Delivery . price , Delivery . product_lines_id , Order . id , Order . user_id , Order . product_lines_id , Order . order_date , Order . deliver_monday , Order . deliver_tuesday , Order . deliver_wednessday , Order . deliver_thursday , Order . deliver_friday , Order . deliver_saturday , Order . delivery_address_id , Order . payment_delay , Order . active , Order . cancle_date , Order . replaced_order_id , Order . created , Order . modified , DeliveryAddress . id , DeliveryAddress . delivery_company , DeliveryAddress . delivery_title , DeliveryAddress . delivery_first_name , DeliveryAddress . delivery_last_name , DeliveryAddress . delivery_street , DeliveryAddress . delivery_house_nr , DeliveryAddress . delivery_postal_code , DeliveryAddress . delivery_town , DeliveryAddress . delivery_country , DeliveryAddress . created , DeliveryAddress . deleted , DeliveryAddress . modified , ProductLine . id , ProductLine . name , ProductLine . description , ProductMix1 . id , ProductMix1 . name , ProductMix1 . description , ProductMix1 . image_small_path , ProductMix1 . image_normal_path , ProductMix1 . product_categories_id , ProductMix1 . depricated , ProductMix1 . created , ProductMix1 . modified , ProductMix2 . id , ProductMix2 . name , ProductMix2 . description , ProductMix2 . image_small_path , ProductMix2 . image_normal_path , ProductMix2 . product_categories_id , ProductMix2 . depricated , ProductMix2 . created , ProductMix2 . modified , ProductMix3 . id , ProductMix3 . name , ProductMix3 . description , ProductMix3 . image_small_path , ProductMix3 . image_normal_path , ProductMix3 . product_categories_id , ProductMix3 . depricated , ProductMix3 . created , ProductMix3 . modified , ProductMix4 . id , ProductMix4 . name , ProductMix4 . description , ProductMix4 . image_small_path , ProductMix4 . image_normal_path , ProductMix4 . product_categories_id , ProductMix4 . depricated , ProductMix4 . created , ProductMix4 . modified FROM deliveries AS Delivery LEFT JOIN orders AS Order ON (Delivery . order_id = Order . id) LEFT JOIN delivery_addresses AS DeliveryAddress ON (Delivery . delivery_address_id = DeliveryAddress . id) LEFT JOIN product_lines AS ProductLine ON (Delivery . product_lines_id = ProductLine . id) LEFT JOIN product_mixes AS ProductMix1 ON (Delivery . product_mix_id1 = ProductMix1 . id) LEFT JOIN product_mixes AS ProductMix2 ON (Delivery . product_mix_id2 = ProductMix2 . id) LEFT JOIN product_mixes AS ProductMix3 ON (Delivery . product_mix_id3 = ProductMix3 . id) LEFT JOIN product_mixes AS ProductMix4 ON (Delivery . product_mix_id4 = ProductMix4 . id) WHERE User . id = 1

誰もケーキが2番目のレベルを引っ張ってこない理由を知っていますか?この場合、ユーザーモデルは再帰的に5に設定されていますか?

多くのありがとうございます。

+0

あなたはモデルのキャッシュ(複数可)を削除しようとしたことがありますか? – Ross

答えて

0

EDIT:ちょうどあなたがOrder.user_id(代わりのUser.id)によってフィルタリングすることができるよう、あなたのケースであなたは、実際に第二レベルJOINを必要としないことを私に起こりました!私のポイントが見えますか?

おそらく以下の解決策は必要ありません。第二レベル(深い)にフィルタリング(条件)のために、私はjoinsを使用するよう


は、私の知る限りでは、ケーキは決して、第二レベルJOIN自体もしません。ご例えば

$options['joins'] = array(
    array(
     'table' => 'orders', 
     'alias' => 'Order', 
     'type' => 'LEFT', 
     'conditions' => array(
      'Order.id = Delivery.order_id', 
     ) 
    ), 
    array(
     'table' => 'users', 
     'alias' => 'User', 
     'type' => 'LEFT', 
     'conditions' => array(
      'User.id = Order.user_id', 
      'User.some_field' => $someFilteringValue 
     ) 
    ) 
); 
$result = $this->Delivery->find('all', $options); 
関連する問題