Database 带spreep的多连接查询 让我们考虑下面的表格: special_product( id product_key - FK to product.key) product( id key name) product_attributes( id product_id FK to product.id description )
我的问题是如何编写一个查询,从Database 带spreep的多连接查询 让我们考虑下面的表格: special_product( id product_key - FK to product.key) product( id key name) product_attributes( id product_id FK to product.id description ),database,zend-framework,orm,propel,Database,Zend Framework,Orm,Propel,我的问题是如何编写一个查询,从SpecialProductQuery类开始,为我提供列special\u product.id、product.id、product\u attributes.description 基本上,生成的查询应该是 select s.id, p.id, pa.description from special_product s left join product p on s.key = p.key left join product_attributes pa on
SpecialProductQuery
类开始,为我提供列special\u product.id、product.id、product\u attributes.description
基本上,生成的查询应该是
select s.id, p.id, pa.description
from special_product s
left join product p on s.key = p.key
left join product_attributes pa on p.id = pa.product_id
假设您已经在模式中建立了关系,您应该能够:
$specialProduct = specialProductQuery::create()
->joinWithProduct(SpecialProduct.Product)
->joinWith(Product.ProductAttributes)
->find();
从这里,您可以从子对象中获得所需的任何值(请记住,您仍然需要遍历集合):
YMMV取决于您如何命名您的模型
foreach($specialProduct as $special)
{
$product = $special->getProduct();
}