我使用symfony 1.4.15和doctrine。我有类别和子类别:Symfony从类别和子类别中获取记录
Category:
actAs:
Timestampable: ~
Sluggable:
unique: true
canUpdate: true
fields: [name]
builder: [myTools, StripText]
I18n:
fields: [name]
columns:
name: { type: string(255), notnull: true }
Subcategory:
actAs:
Timestampable: ~
Sluggable:
unique: true
canUpdate: true
fields: [name]
builder: [myTools, StripText]
I18n:
fields: [name]
columns:
category_id: { type: integer() }
name: { type: string(255), notnull: true }
relations:
Category: { onDelete: CASCADE,local: category_id , foreign: id }
而且我有产品。产品与类别和子类别有关系。
Product:
actAs:
Timestampable: ~
Sluggable:
unique: true
canUpdate: true
fields: [name]
builder: [myTools, StripText]
I18n:
fields: [name,description,shortbody,meta_keywords,meta_description]
columns:
partner_id: { type: integer() }
active: { type: boolean, default: 0, notnull: false }
name: { type: string(255), notnull: true }
shortbody: { type: string(500), notnull: true }
description: { type: string(), notnull: true }
reference: { type: string(100), notnull: true }
code: { type: string(100), notnull: true }
delivery_period: { type: string(100), notnull: true }
shipping_volume: { type: string(100), notnull: true }
weight: { type: string(100), notnull: true }
packing: { type: string(100), notnull: true }
package_dimensions: { type: string(100), notnull: true }
type_of_packaging: { type: string(100), notnull: true }
video_url: { type: string(100), notnull: false }
meta_keywords: { type: string(255) }
meta_description: { type: string(255) }
relations:
Subcategory: { local: product_id , foreign: subcategory_id, refClass: ProductSubcategory }
Category: { local: product_id , foreign: category_id, refClass: ProductCategory }
Partner: { local: partner_id , foreign: id, onDelete: CASCADE }
ProductSubcategory:
connection: doctrine
columns:
subcategory_id: { type: integer(), primary: true}
product_id: { type: integer(), primary: true }
relations:
Product: { onDelete: CASCADE,local: product_id, foreign: id }
Subcategory: { onDelete: CASCADE,local: subcategory_id, foreign: id }
ProductCategory:
connection: doctrine
columns:
category_id: { type: integer(), primary: true}
product_id: { type: integer(), primary: true }
relations:
Product: { onDelete: CASCADE,local: product_id, foreign: id }
Category: { onDelete: CASCADE,local: category_id, foreign: id }
所以我需要把所有的产品类别和类别(这一个查询) 我可以得到属于类别的所有产品:
$q = $this->createQuery('a')
->andWhere('a.active=1')
->leftJoin('a.ProductCategory o')
->andWhere('o.Category_id=?',$category_id)
->addORDERBY ('created_at DESC');
,但我不现在怎么弄来自所有类别子类别的所有产品....谢谢!
在您的模式中是 - 如果您获得所有带有类别的产品,那么您也具有此类别中所有子类别的产品。如果不是,请添加简单的装置,你想要做什么? –
我可以从类别中获取所有产品,但无法从类别的所有子类别获取所有产品。我需要一个查询。 – denys281
请添加灯具和示例。你的查询应该是如此的工作。 –