cakephp我尝试在cakePHP 1.3中具有许多关联的模型上获得一个查找('all'...),它在第二级递归中具有查询的过滤条件架构。简单来说,它看起来像这样,我想过滤UserId:
Delivery belongsTo Order, Order belongsTo User.
以下是关联:
订单: var $ belongsTo = array(
'User' => array( 'className' => 'User', 'foreignKey' => 'user_id', 'conditions' => '', 'fields' => '', 'order' => '' ),....
送货: var $ belongsTo = array(
'Order' => array( 'className' => 'Order', 'foreignKey' => 'order_id', 'conditions' => '', 'fields' => '', 'order' => '' ),...
产生的错误是:
SQL错误:1054:'where子句'中的未知列'User.id'[CORE / cake / libs / model / datasources / dbo_source.php,第684行]
这里是完整的查询,只是为了好玩:
选择
Delivery
。id
,Delivery
。order_id
,Delivery
。delivery_address_id
,Delivery
。{{1} },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
,{{ 1}}。assembled
,Delivery
。shipped
,Delivery
。rated
,Delivery
。price
,{{1} }。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
。{{ 1}},Order
。deliver_thursday
,Order
。deliver_friday
,Order
。deliver_saturday
,Order
。{{1} },delivery_address_id
。Order
,payment_delay
。Order
,active
。Order
,cancle_date
。Order
,replaced_order_id
。Order
,created
。Order
,modified
。DeliveryAddress
,id
。DeliveryAddress
,{{ 1}}。delivery_company
,DeliveryAddress
。delivery_title
,DeliveryAddress
。delivery_first_name
,DeliveryAddress
。delivery_last_name
,{{1} }。DeliveryAddress
,delivery_street
。DeliveryAddress
,delivery_house_nr
。DeliveryAddress
,delivery_postal_code
。DeliveryAddress
,delivery_town
。DeliveryAddress
,delivery_country
。DeliveryAddress
,created
。DeliveryAddress
,deleted
。DeliveryAddress
,modified
。{{ 1}},ProductLine
。id
,ProductLine
。name
,ProductLine
。description
,ProductMix1
。{{1} },id
。ProductMix1
,name
。ProductMix1
,description
。ProductMix1
,image_small_path
。ProductMix1
,image_normal_path
。ProductMix1
,product_categories_id
。ProductMix1
,depricated
。ProductMix1
,created
。ProductMix1
,{{ 1}}。modified
,ProductMix2
。id
,ProductMix2
。name
,ProductMix2
。description
,{{1} }。ProductMix2
,image_small_path
。ProductMix2
,image_normal_path
。ProductMix2
,product_categories_id
。ProductMix2
,depricated
。ProductMix2
,created
。ProductMix2
,modified
。ProductMix3
,id
。ProductMix3
,name
。{{ 1}},ProductMix3
。description
,{{ 1}}。ProductMix3
,image_small_path
。ProductMix3
,image_normal_path
。ProductMix3
,product_categories_id
。ProductMix3
,{{1} }。depricated
,ProductMix3
。created
,ProductMix3
。modified
,ProductMix4
。id
,ProductMix4
。name
来自ProductMix4
ASdescription
LEFT JOINProductMix4
ASimage_small_path
ON(ProductMix4
。image_normal_path
=ProductMix4
。product_categories_id
)LEFT JOINProductMix4
ASdepricated
ON(ProductMix4
。created
=ProductMix4
。modified
)LEFT JOIN {{1 }deliveries
ON(Delivery
。orders
=Order
。Delivery
)LEFT JOINorder_id
ASOrder
ON({ {1}}。id
=delivery_addresses
。DeliveryAddress
)LEFT JOINDelivery
ASdelivery_address_id
ON(DeliveryAddress
。id
=product_lines
。ProductLine
)LEFT JOINDelivery
ASproduct_lines_id
ON(ProductLine
。id
=product_mixes
。ProductMix1
)LEFT JOINDelivery
ASproduct_mix_id1
ON(ProductMix1
。id
=product_mixes
。ProductMix2
)WHEREDelivery
。{{1 }} = 1
有没有人知道为什么蛋糕没有拉到第二级,在这种情况下是User模型,甚至递归时都设置为5?
非常感谢。
答案 0 :(得分:0)
编辑:我刚刚想到,在您的情况下,您实际上不需要第二级JOIN
,因为您可以按Order.user_id
过滤(而不是{{ 1}})!你明白我的意思吗?
所以你可能不需要下面的解决方案。
据我所知,Cake从不做第二级User.id
本身,所以对于第二级(和更深层次)的过滤(条件),我使用joins
。
对于你的例子:
JOIN