Re: [CDBI] ChildOf

[prev] [thread] [next] [Date index for 2005/09/12]

From: Marcello
Subject: Re: [CDBI] ChildOf
Date: 09:39 on 12 Sep 2005
Kate Yoak ha scritto:
>>This sounds useful, but I don't quite understand from your
>>description how it
>>differs from a has_a relationship from the child to the parent
>>(other than it
>>allows you to specify the accessor name for the parent). What am
>>I missing?
>>
>>I implement similar parent/child relationships like so:
>>
>>Parent->columns('Primary' => qw/parent_id/);
>>Parent->has_many(children => Child);
>>Child->columns('Primary' => qw/child_id/);
>>Child->columns('Others => qw/parent_id/);
>>Child->has_a(parent_id => Parent);
>>
>>How does ChildOf simplify or improve on this?
>>
>>Thanks,
>>Ed
>>
> 
> 
> Good point.  Forgot to explain.  The problem with has_a is that it takes
> your primary column, your object id (that you are probably using everywhere
> in urls, keys, etc) and turns it into a parent object.  That's not very nice
> from two perspectives:
> 
> #1.  I like my id where it is!  :-)  I mean, really - when I say <a
> href="/?a_id=<%$link->link_id%>"> I expect a number to show up. (I believe
> it actually will - because of stringify - but read on).
> 
> #2.  I don't want to go to the database for the parent just because I am
> accessing the child's id.
> 
> OK.  So #1 actually works as-is.  Unless you have a custom stringify, your
> $link->link_id in a string context should show up as a number.  but it does
> so by first going to the database , and then converting the result into the
> number (the #2 issue).  What's worse is - I may choose to override
> stringify - and break a completely independent module - that's not so good.

Maybe I'm misunderstanding something, but my experience is this:
the default stringification of an object gives me its primary key (which 
is usually an integer - let's suppose it's 'id integer auto_increment 
primary key'). If I use the object handle to refer to a particular table 
row and later I choose a different column for stringification I 
obviously don't get the primary key value anymore.
But if I write:
<a href="[%base _ controller _ '/view/' _ object->id%]">[%object%]</a>
then I can choose how to stringify $object as I see fit, and still get 
the corrent href because I explicitly require the value of the object's
primary key colyumn.

HTH,

Marcello

> 
> All that said, has_a certainly has a place.  It is what gave me the idea,
> and I used it heavily to figure out how to make my code work.
> 
> I am looking forward to any disagreements to the arguments above.  I am very
> new to cdbi (shame on me) and may miss something important.
> 
> 
> 
> _______________________________________________
> ClassDBI mailing list
> ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
> http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi
> 


_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

[CDBI] ChildOf
Kate Yoak 23:24 on 09 Sep 2005

[CDBI] Re: ChildOf
Edward J. Sabol 23:52 on 09 Sep 2005

RE: [CDBI] ChildOf
Kate Yoak 00:09 on 10 Sep 2005

Re: [CDBI] ChildOf
Matt S Trout 13:53 on 11 Sep 2005

Re: [CDBI] ChildOf
Marcello 09:39 on 12 Sep 2005

Re: [CDBI] ChildOf
merlyn (Randal L. Schwartz) 14:27 on 12 Sep 2005

RE: [CDBI] ChildOf
Kate Yoak 19:55 on 13 Sep 2005

Re: [CDBI] ChildOf
William Ross 13:58 on 10 Sep 2005

Generated at 23:46 on 13 Sep 2005 by mariachi v0.52