Monday, November 1, 2010

Re: Anything wrong with this?

Everything in your database should have an id column, regardless of if
it's in a relationship or not. This is the only thing that can
uniquely identify your row if you want to edit it, delete it,
etc... :)

Then, to follow cake conventions, any relationship should have a
foreign key column of <parentmodel>_id . Following these conventions
will make your life a 100 times easier in the long run, and is
generally good practice!

Cheers!

On Nov 1, 8:58 pm, "Dave Maharaj" <m...@davemaharaj.com> wrote:
> User hasOne Profile , Profile belongsTo User
>
> But in my Profile table I do not have user_id, I just have id which is the
> User.id created automatically when the User creates an account. To me it
> seems like why give the Profile a separate ID when essentially its just an
> extension of the User.
>
> Everything else is related to the Profile
>
> Profile:
>
> var $belongsTo = array(
>
> 'User' => array(
>
>                                 'className' => 'User',
>
>                                 'foreignKey' => 'user_id')
>
> );
>
> User:
>
> var $hasOne = array(
>
> 'Role' => array(
>
>                                 'className' => 'Role',
>
>                                 'foreignKey' => 'id',
>
>                                 'dependent' => false),
>
>                 'Profile' => array(
>
>                                 'className' => 'Profile',
>
>                                 'foreignKey' => 'id',
>
>                                 'dependent' => false)
>
> );
>
> Is this set up wrong?
>
> Thanks,
>
> Dave

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: