[CDBI] ChildOf

William Ross will at spanner.org
Sat Sep 10 14:58:04 BST 2005


On 10 Sep 2005, at 00:24, Kate Yoak wrote:


> ...::Relationship::ChildOf - child_of is a type of relationship that's
> frequently encountered between parent/child entities:  company =>  
> employee;
> advertiser => ad; cluster => server, etc.
>


Ed is right: that's exactly a has_a relationship, and would usually  
come with a reciprocal has_many. Has_a is really the core of cdbi and  
where it all started: one would need a *very* good reason not to use  
it here.

By the way, retrieving a has_a related column doesn't make cdbi go  
back to the database. All it does is bless a minimal hashref (just  
the primary key) into the foreign class, and return the resulting  
object. The docs refer to this as 'lazy loading': there is no  
database access involved unless you go on to call columns of the new  
object.

The only overhead from this:

     this bison belongs to <a href="/foo?person=[% bison.person 
%]">someone</a>

is from the creation and stringification of the person object,  
whereas this:

     this bison belongs to <a href="/foo?person=[% bison.person %]"> 
[% thing.person.first_name %]</a>

also involves a SELECT call to retrieve the person's first_name (and  
everything else in that column group).

Personally I think that if you're using Class::DBI you've already  
given up any hope of optimisation and might as well enjoy the  
convenience.


> $link->page->website->company->account :)
> While that does seem a little silly (and is not really the intent, it
> demonstrates the idea.
>

I don't think that's silly at all. Or rather, I do it all the time.  
Perhaps it's also silly.

best

will






More information about the ClassDBI mailing list