[Dbix-class] Difference between belongs_to and has_one

Drew Taylor taylor.andrew.j at gmail.com
Thu Oct 19 19:10:18 CEST 2006


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."

I'm sure I said that in a very ineloquent way, but hopefully you get the idea.

Drew

On 10/19/06, Lee Standen <nom at standen.id.au> wrote:
> Belongs to is a child -> parent relationship
> Has one is a sibling <-> sibling relationship?
>
> I'm just guessing here.
>
> My response #2 would be that one is an alias for another
>
>
>
> On Thu, 19 Oct 2006, Drew Taylor wrote:
>
> > This morning I was doing some work on relationships and ran into this question:
> > What is the difference between belongs_to and has_one/might_have?
> >
> > They seem VERY similar. AFAICT the fundamental difference is that with
> > belongs_to cascading delete is turned off, while with has_one
> > cascading delete is turned on by default. Is there any other
> > differences between these two?
> >
> > Thanks,
> > Drew
> > --
> > ----------------------------------------------------------------
> > Drew Taylor                 *  Web development & consulting
> > Email: drew at drewtaylor.com  *  Site implementation & hosting
> > Web  : www.drewtaylor.com   *  perl/mod_perl/DBI/mysql/postgres
> > ----------------------------------------------------------------
> >
> > _______________________________________________
> > List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> > Wiki: http://dbix-class.shadowcatsystems.co.uk/
> > IRC: irc.perl.org#dbix-class
> > SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> > Searchable Archive: http://www.mail-archive.com/dbix-class@lists.rawmode.org/
> >
> >
>
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive: http://www.mail-archive.com/dbix-class@lists.rawmode.org/
>


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