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: [email protected] [mailto:[email protected]] On Behalf
Of [email protected]
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" <[email protected]> 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: [email protected] [mailto:[email protected]] 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 [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
-~----------~----~----~----~------~----~------~--~---

Reply via email to