Friday, August 31, 2012

Re: Wordplay Messing thing up

On Fri, Aug 31, 2012 at 1:53 AM, Advantage+ <movepixels@gmail.com> wrote:
> User belongsTo Group
> Group hasMany User
>
> Sounds fine,
>
> User hasOne Role
> Role hasMany User
>
> Depending on the word Group / Role the relationship changes to sound correct
> when you say it.
>
> So what is correct when I want my User belongs to a Group? Or my User has
> One Role?
>
> Where Group or Role is (admin, manager, editor)

The first one is the correct one. Going from the manual
(http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html),
you only use hasOne in a one-to-one relationship. To me that means
that you can have

User hasOne Role
Role belongsTo User

But if you want the user to have more than one role, use something like

User hasMany Roles
Role belongsTo User

But, unfortunately that means that we can't share Roles between Users.
Each User has exclusive rights to the Role(s) that they are assigned.
We would probably want something more like this

User hasAndBelongsToMany Roles
Role hasAndBelongsToMany Users

This means that a User can have multiple Roles and each Role can be
shared between multiple users. This way does need a linking table
though (Roles_Users)

I hope this helps.

Mike.

--
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 cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.

No comments: