"what would happen if both used hasOne or belongsTo?"
For starters, I don't think cake would like it too much.

I'm not sure why u would even ask that question; Are you asking if you
could put a FK for-each-table, in-each-table? Are you asking if you
can use hasOne in the models, on both sides of the same relationship?
Or are you asking if you can simply refer to hasOne as belongsTo and
vice versa? In any case it doesn't seem to make much sense to me.

As a side note:
I may be wrong about this.... as far db theory is concerned,  I don't
think there is any technical difference in hasOne and belongsTo. It is
simply a one-to-one relationship. HasOne and belongsTo are simply a
way for cake to specify how to models are linked in the database/
models.



On Apr 10, 11:18 am, Sergei Gerasenko <[EMAIL PROTECTED]>
wrote:
> Very good answer. Thanks for taking the time.
>
> In that example, what would happen if both used hasOne or belongsTo? Why
> would that be wrong?
>
> Just trying to understand this better. I'm a little rusty on my DB
> theory.
>
>
>
> On Tue, Apr 10, 2007 at 02:59:45PM -0000, [EMAIL PROTECTED] wrote:
>
> > "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...
>
> --
>
> Sergei Gerasenko
> IT Department
> PublicSchoolWORKS
> Phone: (513)-631-6111


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