Use ContainableBehavior:

$this->User->find(
        'first',
        array(
                'conditions' => array(
                        'User.id' => $user_id
                ),
                'contain' => array(
                        'Product'
                )
        )
);

On Mon, Jun 8, 2009 at 11:47 AM, Céryl<c.a.h.wilt...@student.tue.nl> wrote:
>
> Ah, i saw it often, but I nevert had to use that link.
> Thansk for the fast reply!
>
> This Googlegroup never let's me down! :D
>
> Anyway, it works, I get the right array from the database now, but how
> can I make a SQL-query on this relationship that let's me get all the
> products by a certain user?
> I prefer to have the call in the users_controller.
>
> I tried something like this:
> function getitemlistfor($id) {
>
> $data = $this->User->Product->find('all', array('fields'=>'Product.*',
> 'conditions'=>array(?????);
>
> debug($data);
> $this->set('data', $data);
> }
>
> I'm not sure on the conditions. I tried a lot, but nothing seems to do
> the trick.
>
> I need to get an array that get's the information of all products that
> belong to user $id.
>
> Thanks!
>
> On 8 jun, 16:15, Martin Westin <martin.westin...@gmail.com> wrote:
>> $hasAndBelongsToMany
>>
>> A User can have many Product(s) in hist "shopping cart" or something.
>> A Product can be in (have) many User's carts.
>>
>> On Jun 8, 4:03 pm, Céryl <c.a.h.wilt...@student.tue.nl> wrote:
>>
>> > Hello all,
>>
>> > Little question:
>>
>> > Say, i have two tables, USERS and PRODUCTS, for arguments sake.
>>
>> > Now, all the products in the PRODUCTS table are unique by some value,
>> > say barcode, so it doesn't allow duplicates of the same product in the
>> > table.
>>
>> > Now, a user can have several products associated with him. What is the
>> > best way to do this? Eventually a user would be able to log in and get
>> > an overview of his selected products, and add/remove products to his
>> > personal list from all the products in the PRODUCT table.
>>
>> > A table that holds user_id in one column, and product_id in the other,
>> > maybe? But that would grow to a very large redundant table like this:
>> > user product
>> > 1         3
>> > 1         6
>> > 2         3
>> > 2         4
>> > 2         5
>> > Etc.
>>
>> > Any idea's?
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to