Re: A little help needed on determining my model relation ships please
ok here is how you should do that create you category table first then create your product table in the product table just include category_id then you can do product belongs to category or cake bake it it will ask you what model associations let me know how you did On Jun 4, 6:45 am, Beedge cake...@hbit.ie wrote: Hi all, about to start on my first cake project. A straight forward e- commerce site. I am not used to having to visualise my database relationships so I was hoping for a little help. A product belongs in a category A product can be in many categories A Category has Sub categories Is this just a HABTM relationship between products and categories? I will be using tree behavior for my categories. Any comments on this or helpers? I would love to find a tutorial that covered this, but all I can really find is blog tutorials! Thanks in advance Kev --~--~-~--~~~---~--~~ 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: A little help needed on determining my model relation ships please
This depends on how you want to build your sub categories tree: Is it a relationship like this: category id parent_id or category id sub_category id category_id parent_sub_category your product could be product id ... Then a join table categories_products id product_id category_id or you could have product id category_id product_sub_categories id product_id sub_category_id it really depends on what your data model requirements are. The join table will be extremely useful in establishing the HABTM relationships you require. Cake bake will not automatically detect recursive parent_id as a category. so you will have to define that manually. -Original Message- From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of Beedge Sent: 2009-06-04 10:46 To: CakePHP Subject: A little help needed on determining my model relation ships please Hi all, about to start on my first cake project. A straight forward e- commerce site. I am not used to having to visualise my database relationships so I was hoping for a little help. A product belongs in a category A product can be in many categories A Category has Sub categories Is this just a HABTM relationship between products and categories? I will be using tree behavior for my categories. Any comments on this or helpers? I would love to find a tutorial that covered this, but all I can really find is blog tutorials! Thanks in advance Kev --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~--- inline: image001.gif
Re: A little help needed on determining my model relation ships please
Ok I think I follow, just to clarify: A product will belong to at least one or more subcategories, so i guess it will be product_sub_categories id product_id sub_category_id Im not too sure what you mean by the recursive parent_id.. can you please elaborate? Thanks Kevin On Jun 4, 3:02 pm, David Coleman david.cole...@connaxis.com wrote: This depends on how you want to build your sub categories tree: Is it a relationship like this: category id parent_id or category id sub_category id category_id parent_sub_category your product could be product id ... Then a join table categories_products id product_id category_id or you could have product id category_id product_sub_categories id product_id sub_category_id it really depends on what your data model requirements are. The join table will be extremely useful in establishing the HABTM relationships you require. Cake bake will not automatically detect recursive parent_id as a category. so you will have to define that manually. -Original Message- From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of Beedge Sent: 2009-06-04 10:46 To: CakePHP Subject: A little help needed on determining my model relation ships please Hi all, about to start on my first cake project. A straight forward e- commerce site. I am not used to having to visualise my database relationships so I was hoping for a little help. A product belongs in a category A product can be in many categories A Category has Sub categories Is this just a HABTM relationship between products and categories? I will be using tree behavior for my categories. Any comments on this or helpers? I would love to find a tutorial that covered this, but all I can really find is blog tutorials! Thanks in advance Kev image001.gif 1KViewDownload --~--~-~--~~~---~--~~ 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: A little help needed on determining my model relation ships please
The recursive refers to whether or not you want sub_categories to have other sub_categories... Products belong to categories, so I suggested a separate category table to handle that relationship, Then sub categories are related to a category of course, but you have a HABTM relationship with the product. It could be all done with a recursive category table, but it would complicate the cake relationships. Especially when you start traversing deep into sub-sub-categories... So I suggested that you have Product.cat_id - category.id Product.id -( product_sub_categories.prod_id Product_sub_categories.sub_cat_id )- sub_category.id then you can have sub_category.cat_id - category.id and sub_category.parent_id - sub_category.id and you are very-happy-super-tree-enabled! :-) Cheers, Dave -Original Message- From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of cake...@hbit.ie Sent: 2009-06-04 11:57 To: CakePHP Subject: Re: A little help needed on determining my model relation ships please Ok I think I follow, just to clarify: A product will belong to at least one or more subcategories, so i guess it will be product_sub_categories id product_id sub_category_id Im not too sure what you mean by the recursive parent_id.. can you please elaborate? Thanks Kevin On Jun 4, 3:02 pm, David Coleman david.cole...@connaxis.com wrote: This depends on how you want to build your sub categories tree: Is it a relationship like this: category id parent_id or category id sub_category id category_id parent_sub_category your product could be product id ... Then a join table categories_products id product_id category_id or you could have product id category_id product_sub_categories id product_id sub_category_id it really depends on what your data model requirements are. The join table will be extremely useful in establishing the HABTM relationships you require. Cake bake will not automatically detect recursive parent_id as a category. so you will have to define that manually. -Original Message- From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of Beedge Sent: 2009-06-04 10:46 To: CakePHP Subject: A little help needed on determining my model relation ships please Hi all, about to start on my first cake project. A straight forward e- commerce site. I am not used to having to visualise my database relationships so I was hoping for a little help. A product belongs in a category A product can be in many categories A Category has Sub categories Is this just a HABTM relationship between products and categories? I will be using tree behavior for my categories. Any comments on this or helpers? I would love to find a tutorial that covered this, but all I can really find is blog tutorials! Thanks in advance Kev image001.gif 1KViewDownload --~--~-~--~~~---~--~~ 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: A little help needed on determining my model relation ships please
FYI: I suggested the relationship of product - category because it will simplify queries, and help facilitate the frontend in most cases. When dealing with a nested tree data model such as this, you want to consider the load of your joins on the database, and take some precautions to lower the execution cost of joins. Having the 2 separate relationships will also make it easier to work with the data in cake, due to the way that cake will assemble results and access the data. Cake is not good for dealing with deep recursion, so you want to try and avoid basing your application on queries that will have conditions on tables joined to tables which are joined to the current model. By default, cake only will join immediate descendents. It can join deeper with careful model construction, but it is more work than it is worth. Careful database schema planning can ease the task of getting your data with a minimum of custom coding and a minimum of execution overhead for php/cake/and sql. :-) Cheers - D -Original Message- From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of cake...@hbit.ie Sent: 2009-06-04 11:57 To: CakePHP Subject: Re: A little help needed on determining my model relation ships please Ok I think I follow, just to clarify: A product will belong to at least one or more subcategories, so i guess it will be product_sub_categories id product_id sub_category_id Im not too sure what you mean by the recursive parent_id.. can you please elaborate? Thanks Kevin On Jun 4, 3:02 pm, David Coleman david.cole...@connaxis.com wrote: This depends on how you want to build your sub categories tree: Is it a relationship like this: category id parent_id or category id sub_category id category_id parent_sub_category your product could be product id ... Then a join table categories_products id product_id category_id or you could have product id category_id product_sub_categories id product_id sub_category_id it really depends on what your data model requirements are. The join table will be extremely useful in establishing the HABTM relationships you require. Cake bake will not automatically detect recursive parent_id as a category. so you will have to define that manually. -Original Message- From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of Beedge Sent: 2009-06-04 10:46 To: CakePHP Subject: A little help needed on determining my model relation ships please Hi all, about to start on my first cake project. A straight forward e- commerce site. I am not used to having to visualise my database relationships so I was hoping for a little help. A product belongs in a category A product can be in many categories A Category has Sub categories Is this just a HABTM relationship between products and categories? I will be using tree behavior for my categories. Any comments on this or helpers? I would love to find a tutorial that covered this, but all I can really find is blog tutorials! Thanks in advance Kev image001.gif 1KViewDownload --~--~-~--~~~---~--~~ 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: A little help needed on determining my model relation ships please
Resending because for some reason my 2nd message appeared and this one is not in the list yet. :-( The recursive refers to whether or not you want sub_categories to have other sub_categories... Products belong to categories, so I suggested a separate category table to handle that relationship, Then sub categories are related to a category of course, but you have a HABTM relationship with the product. It could be all done with a recursive category table, but it would complicate the cake relationships. Especially when you start traversing deep into sub-sub-categories... So I suggested that you have Product.cat_id - category.id Product.id -( product_sub_categories.prod_id Product_sub_categories.sub_cat_id )- sub_category.id then you can have sub_category.cat_id - category.id and sub_category.parent_id - sub_category.id and you are very-happy-super-tree-enabled! :-) Cheers, Dave -Original Message- From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of cake...@hbit.ie Sent: 2009-06-04 11:57 To: CakePHP Subject: Re: A little help needed on determining my model relation ships please Ok I think I follow, just to clarify: A product will belong to at least one or more subcategories, so i guess it will be product_sub_categories id product_id sub_category_id Im not too sure what you mean by the recursive parent_id.. can you please elaborate? Thanks Kevin On Jun 4, 3:02 pm, David Coleman david.cole...@connaxis.com wrote: This depends on how you want to build your sub categories tree: Is it a relationship like this: category id parent_id or category id sub_category id category_id parent_sub_category your product could be product id ... Then a join table categories_products id product_id category_id or you could have product id category_id product_sub_categories id product_id sub_category_id it really depends on what your data model requirements are. The join table will be extremely useful in establishing the HABTM relationships you require. Cake bake will not automatically detect recursive parent_id as a category. so you will have to define that manually. -Original Message- From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of Beedge Sent: 2009-06-04 10:46 To: CakePHP Subject: A little help needed on determining my model relation ships please Hi all, about to start on my first cake project. A straight forward e- commerce site. I am not used to having to visualise my database relationships so I was hoping for a little help. A product belongs in a category A product can be in many categories A Category has Sub categories Is this just a HABTM relationship between products and categories? I will be using tree behavior for my categories. Any comments on this or helpers? I would love to find a tutorial that covered this, but all I can really find is blog tutorials! Thanks in advance Kev image001.gif 1KViewDownload --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---