Try:
$this->User->find('all', array(
'contain' => array('Brand' => array('Product'))
));
1) Read the Book. Chances are it'll have the information you're
looking for. http://book.cakephp.org/view/474/Containable
2) Look at the test cases for the behavior in question.
http://api.cakephp.org/tests/class_containable_test.html
3) Google is always available. 'cakephp containable' returns 20k
results; I'm sure some of them are useful.
> Is CakePHP very complex for writing function for such query..because I
> am trying it from last two days also no body is replaying me.
People on this list answer questions in their own free time; you pay
nothing to ask the questions and get an answer, and the risk is that
you might not get one. Complaining is not going to help. If that's a
problem, paid consultants are no scarce.
-J.
On Oct 16, 5:31 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> I know what query can return my answer..it's here:
>
> SELECT `Product`.`id`, `Product`.`product_name`, `Brand`.`brand_name`,
> `Brand`.`id`, `ProductsUser`.`user_id`, `ProductsUser`.`product_id`
> FROM `products` AS `Product` JOIN `products_users` AS `ProductsUser`
> ON (`ProductsUser`.`user_id` = 2 AND `ProductsUser`.`product_id` =
> `Product`.`id`) JOIN `brands_products` AS `BrandsProduct` ON
> (`BrandsProduct`.`product_id` = `Product`.`id`) JOIN `brands` AS
> `Brand` ON (`Brand`.`id` = `BrandsProduct`.`brand_id`) WHERE 1 = 1
>
> This query is working fine but I don't know how to write it in
> CakePHP...
>
> I found all products accordingly users by using Containable behavior
> but can not find complete solution.
>
> code is:
> $this->User->contain(array('Product'));
> debug($this->User->find('all', array('conditions' => array('User.id'
> => $this->Auth->user('id')))));
>
> But now don't know how to find all brands accordingly a users product?
>
> Is CakePHP very complex for writing function for such query..because I
> am trying it from last two days also no body is replaying me.
>
> Please tell me how should I go ahead with this?
>
> Thanks
>
> On Oct 16, 12:18 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > Sorry, I forget that I used this solution but could not succeed
>
> > $brands = $this->User->Product->Brand->find('all',array(
> > 'fields' =>
> > array('Brand.id','Brand.brand_name'),
> > 'conditions' =>
> > array('User.id' => $this->Auth->user('id')),
> > 'recersive' => 0)
> > );
>
> > Please help me
>
> > On Oct 16, 12:15 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> > wrote:
>
> > > Hi,
>
> > > I have three Model with following association
> > > 1 User
> > > 2 Product
> > > 3 Brand
>
> > > User ------------HABTM (brands_users)----------Brand
> > > Brand-----------HABTM (brands_products)----------Product
> > > User-----------HABTM (products_users)----------Product
>
> > > I want to find a list of all brands which product had been selected by
> > > a user.
>
> > > Means first user select some products then he will be select brands.
>
> > > So I am unable to display all brands accordingly user's products
>
> > > Thanks a lot you for my help
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---