Items, Attributes,Taxonomies, Taxonomy_attributes,Item_attributes.
Taxonomy_attributes有兩個字段attribute_id(這是一個外鍵的屬性表的ID)和taxonomy_id(這是一個外鍵分類表的ID) 。 另一方面,Item_attributes有兩個字段attribute_id(它是ID屬性表的外鍵)和item_id(它是ID項表的外鍵)。 屬性表具有以下字段: - 名稱,類型和可檢查(可以是0或1)。 項目表具有字段ID和模型。 分類標準表具有字段if和name。
我想向屬性模型添加一個方法,該方法返回所有可檢查等於1的屬性的列表,並加入項目和分類,返回項目模型&分類名稱爲每個屬性。
我的代碼如下: -
public function getCheckables($checkable)
{
$data = $this->find('all',array(
'fields' => array('Attribute.name', 'Attribute.type', 'Item.model', 'Taxonomy.name'),
'conditions' => array('Attribute.checkable' => 1),
'joins' => array(
array(
'table' => 'item_attributes',
'alias' => 'ItemAttribute',
'type' => 'INNER',
'conditions' => 'ItemAttribute.Item_id = Item.id',
),
array(
'table' => 'items',
'alias' => 'Item',
'type' => 'INNER',
'conditions' => 'ItemAttribute.item_id = Item.id'
),
array(
'table' => 'taxonomy_attributes',
'alias' => 'TaxonomyAttribute',
'type' => 'INNER',
'conditions' => 'TaxonomyAttribute.Taxonomy_id = Taxonomy.id'
)
),
'recursive'=>-1
)
);
pr($data); die();
}
可有人指導我用正確的代碼?
你有沒有在你的模型中定義與其他3任何樣的關係? – Tanatos