Re: [newbie] Defining a relationship using Cake's models

2007-08-13 Thread Langdon Stevenson

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
-~--~~~~--~~--~--~---



[newbie] Defining a relationship using Cake's models

2007-08-13 Thread Andrea Spadaccini

Hello everybody,
I'm a newbie to this wonderful framework, and I'm finding it more and
more interesting.

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.

Can anybody help me please?

I should also model a "Hirings" entity table, with a worker_id, a
site_id and a contract_id: suggestions are VERY welcome...

Thanks in advance and sorry for the dumb question!

--
Andrea Spadaccini


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---