Re: The best database setup for this?
Agreed with Brian. It may seem like the table is getting huge (which it eventually will). But you're just keeping record of 2-3 INT data types (depending on how you do the key), so much of it will fit into memory anyhow. I wouldn't worry too much about join tables being a source of slowness (until it is; but it doesn't sound like you're anywhere close to that right now). On Jun 8, 9:36 am, brian wrote: > On Mon, Jun 8, 2009 at 10:03 AM, Céryl wrote: > > > 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. > > That's not redundant. The purpose of a join table is to associate 2 > (or more) other tables. While some fields may contain the same values, > each row, as a whole, should be unique. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: The best database setup for this?
On Mon, Jun 8, 2009 at 10:03 AM, Céryl wrote: > > 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. > That's not redundant. The purpose of a join table is to associate 2 (or more) other tables. While some fields may contain the same values, each row, as a whole, should be unique. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: The best database setup for this?
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 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 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 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 -~--~~~~--~~--~--~---
Re: The best database setup for this?
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 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 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 -~--~~~~--~~--~--~---
Re: The best database setup for this?
$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 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 -~--~~~~--~~--~--~---
The best database setup for this?
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 -~--~~~~--~~--~--~---