I have Tables
Items, Attributes,Taxonomies, Taxonomy_attributes,Item_attributes.
Taxonomy_attributes have two fields attribute_id(which is a foreign key to id of attributes table) and taxonomy_id (which is a foreign key to id of taxonomies table). On the other hand Item_attributes have two fields attribute_id(which is a foreign key to id attributes table) and item_id (which is a foreign key to of id items table). Attributes table have following fields :- Name, Type and Checkable(which is either 0 or 1). Items table have fields id and model. Taxonomies table have fields if and name.
I want to add a method to Attribute model ,that returns list of all attributes with checkable equals 1 and join with items and taxonomies ,that return item model & taxonomy name for each attribute.
My code is as follows:-
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();
}
Can anybody guide me with the right code?