Hi Andrea Andrea Spadaccini wrote: > Ciao Langdon, > >>> In a "traditional" way, I would create a N-N relationships, with an >>> intermediate table that contains a worker_id, a site_id, a date and >>> the number of hours. In fact, I already created this table, adding the >>> mandatory "id" field that Cake wants, but I can't translate it to a >>> Model. >> I would set it up this way: >> >> Three models: >> >> - worker >> - presence >> - site >> >> worker -> hasMany -> presence >> >> presence -> belongsTo -> site >> presence -> belongsTo -> worker >> >> site -> hasMany -> presence >> >> It sounds like you already have the foreign keys worked out. >> >> This should cover your needs. Now you can create a "presence" instance >> and assign a site and a worker to it. Presences can be looked up by >> site, or worker, or site, or worker can be looked up by presence. > > Thanks a lot, I'll go implement my models using your suggestion! > In fact, this blog post also suggests to do as you told me: > > http://www.thinkingphp.org/2006/10/26/modeling-relationships-in-cakephp-faking-rails-throughassociation/ > > .. but being new at CakePHP I thought to model it as an HABTM > relationship. > So please correct me: I shouldn't use a HABTM relationship because in > that way > I couldn't set up other attributes for the relationship itself (the > presence), > right?
That is correct. Just use hasMany and belongsTo relationships with three models, instead of HABTM relationships with two models. Regards, Langdon --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" 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 -~----------~----~----~----~------~----~------~--~---
