"HABTM is only meant for 2 entities. How can you tell
cake to handle a relationship of more than 2 entities (i.e. the join
table has 3 or more foreign keys)?"

You can access more fields in a HABTM join table using the "with" key
in the HABTM relationship definition. I've only used extra fields in a
join table to contain meta data about the relationship though, not
additional foreign keys. You bring up a good point, creating a 3 Model
join would be tricky at best using HABTM, It would be tricky any way
you implement it. You could use "with" property to join the 3rd model,
but if this were the case, you could ony retrieve the id, you couldn't
get at the 3rd model recursively. If you defined the 3 join table as a
model, then you'd be able to get at the data recursively, but you'd
run into the data validation problems I mentioned above.

On May 1, 1:31 am, zonium <[EMAIL PROTECTED]> wrote:
> 1. Many times I create a complete MVC for the join table, especially
> when I need to build complicated/flexible admin interfaces to work
> directly with additional fields in the join table.
> 2. I am not sure if cake can handle compound primary key of more than
> 2 foreign keys. HABTM is only meant for 2 entities. How can you tell
> cake to handle a relationship of more than 2 entities (i.e. the join
> table has 3 or more foreign keys)?
>
> Zonium
>
> On 30 Tháng Tư, 15:23, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > The only real downsides I can see other than complicated code is that
> > join tables will have a compound primary key which I don't think cake
> > can handle very well (ie a primary key of (user_id,post_id)). if
> > instead you use a primary key of id to get around this, and use
> > user_id and post_id as just regular fields, you could very easily end
> > up with duplicate data in your table if you aren't careful(ie two rows
> > where id is different but user_id, post_id are the same). This will
> > cause even more problems when you are trying to delete the M2M
> > relationship, if there are multiple entries for the relationship, when
> > you delete one the others will remain. Also, if you have related data
> > in the join table and you try to grab it by finding the join table
> > entry where user_id=$desiredUID AND post_id=$desiredPID, if there are
> > multiple entries in the table that satisfy these conditions, then the
> > data pulled may be incorrect. This seems like a data validation
> > nightmare to me and using Cakes HABTM relationship takes care of all
> > of these problems.
>
> > Also, I don't see why you'd ever want a controller functions for a
> > join table though. The only time you'd need controller functions for a
> > join table is if you were rendering a view for the join table and
> > you'd definitely never want to do that. If you really wanted functions
> > relating to the join table, they should be defined in the model of the
> > related table and called from the controller that will be rendering
> > the view.
>
> > Restating though, Any data that is related to the join table can be
> > accessesed through a related model using the "with" function so any
> > functions acting on the join table data could be easily implemented in
> > the related Model.
>
> > On Apr 30, 3:57 pm, validkeys <[EMAIL PROTECTED]> wrote:
>
> > > I did it the way that i did it so that I could write controller
> > > actions in the join table controller vs. in the relational tables. I
> > > guess you could just write those actions in the M2M controllers, but
> > > is it not cleaner to write those controller actions directly in the
> > > controller of the join table? Also, it keeps it clean with regards to
> > > creating custom model queries for the join table.
>
> > > David, as we are all trying to learn here, are their any definite
> > > downsides to the way that I am doing it besides the output data?
>
> > > Thanks!
>
> > > On Apr 30, 5:37 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> > > wrote:
>
> > > > The way that validkeys describes is the exact same way that CakePHP
> > > > implements a HABTM relationship. It uses a join table just as
> > > > described. There really is no need to do it the way validkeys
> > > > describes, you don't need a controller and model for the join table,
> > > > it will just make your output data and query conditions that much more
> > > > complicated. If you need to get at extra data in the join table (data
> > > > other than the primary key) use the "with" key in the HABTM
> > > > relationship definition.
>
> > > > On Apr 30, 2:58 pm, validkeys <[EMAIL PROTECTED]> wrote:
>
> > > > > JoC,
>
> > > > > HABTM are good, but another way that I have been modeling M2M
> > > > > relationships is the following:
>
> > > > > assume we had students and classes. One class has many students and
> > > > > one student is in many classes
>
> > > > > classes ------> | classes_students | <---------- students
>
> > > > > 1. create tables for classes, classes_students and students
> > > > > 2. Create models and controllers for all 3 tables (note that the Model
> > > > > for the classes_students would be ClassesStudent)
>
> > > > > Your classes and students models would have many classes_students
>
> > > > > Your classes_students model would belong to classes and students.
>
> > > > > Thats another way to set up the M2M relationship.
>
> > > > > On Apr 29, 11:07 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> > > > > wrote:
>
> > > > > > Cake can handle a many to many relationship just fine. Do a search 
> > > > > > for
> > > > > > HABTM (has and belongs to many) relationship to learn more about how
> > > > > > to do this. Cake has sort of a steep learning curve, especially if 
> > > > > > you
> > > > > > aren't familiar with MVC and OO programming. So, In my opinion Cake
> > > > > > will make this task MUCH easier for someone well versed in Cake or 
> > > > > > at
> > > > > > least well versed in MVC/OO. If you are just learning it will 
> > > > > > probably
> > > > > > make the task moderately easier but any future web programming you 
> > > > > > do
> > > > > > with it will be much easier and faster with Cake than developing
> > > > > > without a framework.
>
> > > > > > Dave
>
> > > > > > On Apr 29, 8:10 am, JoC <[EMAIL PROTECTED]> wrote:
>
> > > > > > > Hello all,
> > > > > > > I am trying to write a maintenance software for a generator
> > > > > > > distributing company.
> > > > > > > The company works the following way
>
> > > > > > > 1 site has many generators
> > > > > > > 1 generators has 1 manufacturer and many parts
> > > > > > > 1 part has many generators
> > > > > > > 1 manufacturer has many generators and many models
> > > > > > > 1 model has one manufacturer
> > > > > > > 1 part works for many generators
> > > > > > > 1 manufacturer makes many models
> > > > > > > .
> > > > > > > .
> > > > > > > .
>
> > > > > > > Anyways as you can see is a very complex system. To which then we 
> > > > > > > will
> > > > > > > add work orders, maintenance, etc..
> > > > > > > My questions is, will cake PHP make my life easier or harder I 
> > > > > > > have
> > > > > > > been working with it for about 1 week and so far its been ok 
> > > > > > > until I
> > > > > > > introduced the above concept today of many parts to many 
> > > > > > > generators
> > > > > > > etc then it got really complex.
>
>
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to