[Dbix-class] Difference between belongs_to and has_one

Drew Taylor taylor.andrew.j at gmail.com
Sat Oct 21 00:01:03 CEST 2006


On 10/20/06, Matt S Trout <dbix-class at trout.me.uk> wrote:
> Drew Taylor wrote:
> > One thing I discovered after my post which I think is CRITICAL:
> > has_one & might_have both use the PK of the local (what's the proper
> > terminology?) table as the FK into the foreign table. Perhaps saying
> > something like this for the might_have docs:
> >
> > "Creates an optional one-to-one relationship with a class, where the
> > primary key of the foreign class is equal to the primary key of the
> > local table. Ie. Foo.id == Bar.id. Unlike belongs_to, might_have ONLY
> > suppports using each tables primary key as the key column."
>
> Erm, except that's not true.
>
> That's what they use for the *default* when they're guessing the join
> condition for you, as documented. If you pass an explicit join condition, they
> do whatever you tell them to.
>
> So clearly an improvement to the docs is "CRITICAL", since even after using it
> you still think it does something different to what it actually does :) maybe
> you could work on a patch in that direction?

I think Jess' reply is nearly there. The critical piece of information
(for me anyway) is the DIRECTION of each relationship. I'll mull it
over this weekend and see if I can come up with something both correct
and coherent. :-)

Drew
-- 
----------------------------------------------------------------
 Drew Taylor                 *  Web development & consulting
 Email: drew at drewtaylor.com  *  Site implementation & hosting
 Web  : www.drewtaylor.com   *  perl/mod_perl/DBI/mysql/postgres
 ----------------------------------------------------------------



More information about the Dbix-class mailing list