Hi Andrea
> I've got a small problem modeling a relationship between my entities
> using Cake's relationships.
>
> Let's say that I have a table of Workers, people who work :), and a
> table of Sites, places where those people must go to work.
>
> I'd like to create a "Presence" relationship between the two entities,
> to track how many hours each person spends daily in each site.
>
> 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.
Hope that helps.
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 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
-~--~~~~--~~--~--~---