I would go away from the HABTM usage and just implement the foreign
key for each parent table in the child table.
You will maybe use a little more space, but you will avoid the
overhead of querying the HABTM table in every query. Also you will be
able to implement cascade delete on the relationships when the parent
is deleted.
Enjoy,
   John


On Apr 9, 6:35 pm, Joshua Taylor <[email protected]> wrote:
> John,
>
> This is not quite accurate.
>
> Contact A would never be associated with more than 1 parent entity.  I
> know that sounds strange, since it is a HABTM relationship.. but what
> I've set up here is a situation where 1 contact table and 1 credential
> table can serve 4 parent entities.  This way I have 2 tables instead
> of 8.
>
> The situation I am trying to create is similar to what you describe.
> If someone deletes a service, the associated records from the
> contacts_services, contacts, credentials_services and credentials
> tables should also be deleted.
>
> I know there are multiple ways to go about that.. I'm just wondering
> what the best way is.
>
> Thanks!
>
> On Apr 8, 1:23 pm, John Andersen <[email protected]> wrote:
>
> > Hmm, I will try to understand what you want to happen using this
> > little example:
>
> > Service A is related HABTM to Contact A
> > Service A is related HABTM to Credential B
> > Service B is related HABTM to Contact A
> > Service B is related HABTM to Credential A
>
> > Let's say that Service A is deleted - do you want automatically also
> > to delete Contact A and Credential B?
>
> > Is the above example something which can happen in your system?
>
> > Enjoy,
> >    John
>
> > On Apr 8, 1:16 am, Joshua Taylor <[email protected]> wrote:> I have a 
> > system with the following logical setup:
>
> > > Machine, Service, Client and Project HABTM Contact and Credential
>
> > > Contact and Credential HABTM Machine, Service, Client and Project
>
> > > It is set up this way so that I can have one table for Contact and
> > > Credential.  This may not be the best way to approach the situation
> > > (I'm no DB guru), so I'm open to suggestions, but I still need to have
> > > a solution for the database schema that I've already set up.
>
> > > So, here's my dilemma (example):
>
> > > If a Service is deleted, I need to delete its associated Contact and
> > > Credential records.
>
> > > Since HABTM relationships don't have a dependency property, how do I
> > > accomplish this (in a non-convoluted way)?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe, reply using "remove me" as the subject.

Reply via email to