Thursday, March 20, 2014

help me to join the table with associative table using hasAndBelongsToMany




i have 4 tables with following data

+ businesses(table 1) its fields are : id, business_name, brand_id

+ categories(table 2) its fields are : id, category_name

+ business_categories(table 3) its fields are : id, business_id , category_id

+ brands(table 4) its fields are id, brand_name

> Business and Category tables are related with business_categories table

I got the correct result of all Business based on Category

my model page Category.php is here pasting

$this->bindModel(
array(
'hasAndBelongsToMany' => array(
'Business' => array(
'className' => 'Business',
'joinTable' => 'business_categories',
'foreignKey' => 'category_id',
'associationForeignKey' => 'business_id',
'with' => 'BusinessCategory'
))));
$category = $this->find('all');

My question is how i can join the Brand(table 4) with Business in this code.

Brand table is related with each Business table brand_id is the primary key(id) of Brand table

Help me please, Thanks in advance.


--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: