"When describing the model for "students", do I think in terms of a
student
having one ethnicity or a student belonging to an ethnicity? "

I think you are asking the wrong question. Perhaps;
"How do my models relate, and how do I represent those relationships?"
Your business rules dictate how your models relate to one another. In
this case we can infer how they relate from common sense.

First thing you must do is decide how your models relate, then you can
represent those relationships with the appropriate  foreign keys in
the appropriate tables. As sumanpaul said: "think as u will relate in
the real world". In which case, student belongs to ethnicity.

With a one-to-one relationship you have the choice of where to put the
foreign key. However to be consistent, put the foreign key in the
model which belongsTo another model. (This is also how bake handles
relationships.)

So if: student belongs to ethnicity, then student table will have a
foreign key for the ethnicity table.
If your student has a profile, then profile belongs to student, so the
profile table should have a student_id foreign key.

Hope that clears things up,
cook

Below are the examples from the manual!
<?php
class User extends AppModel
{
    var $name = 'User';
    var $hasOne = array('Profile' =>
                        array('className'    => 'Profile',
                              'conditions'   => '',
                              'order'        => '',
                              'dependent'    =>  true,
                              'foreignKey'   => 'user_id'
                        )
                  );
}
?>

<?php
class Profile extends AppModel
{
    var $name = 'Profile';
    var $belongsTo = array('User' =>
                           array('className'  => 'User',
                                 'conditions' => '',
                                 'order'      => '',
                                 'foreignKey' => 'user_id'
                           )
                     );
}
?>

On Apr 10, 9:02 am, "sumanpaul" <[EMAIL PROTECTED]> wrote:
> hmm maybe if you paste the query it will help ppl to understand. full
> scenario will be great.
>
> but what I think, when u say students > belongsTo > ethinicity ...you
> are goint to get a dropdown of added ethinicity when u create a new
> student
> and when u view the ethinicity details ...likely url  
> :http://localhost/cakeapp/ethinicity/view/1   ... you are going to get
> the ethinicity details as well as the students belonging to that
> ethinicity.
>
> regards
> suman
>
> On Apr 10, 1:56 am, Sergei Gerasenko <[EMAIL PROTECTED]>
> wrote:
>
> > > student belonging to an ethnicity.
> > > think as u will relate in the real world.
>
> > I'll get back to you on this. I remember that when I specified
> > "belongsTo" in the students model, something strange happened in the
> > query. I need to be at home to test this...


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

Reply via email to