[CDBI] ChildOf

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

From: Kate Yoak
Subject: [CDBI] ChildOf
Date: 23:24 on 09 Sep 2005
I am working on a relationship class which I have found very useful.  Wanted
to throw it out here for critique.

But before I overwhelm everyone with code, I'll explain the motivation.  If
there is interest in the code itself, I'll post it.

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

In each of these pairs the first entity have many second entities; and the
2nd is a child_of first.

__PACKAGE__->child_of ( method_name => Class => foreign_key );

e.g.
---------------------
CDBI::Server->child_of ( cluster => CDBI::Cluster => 'cluster_id');

OR (you could be child of multiple clusters:)

CDBI::Server->child_of ( maintenance_cluster => CDBI::Cluster =>
'mcluster_id');
CDBI::Server->child_of ( web_cluster => CDBI::Cluster => 'wcluster_id');
--------------------
Like might_have, child_of creates the accessor (.e.g web_cluster) which will
return a parent object.

There is only one trigger that i could think of: before_update - we should
really update the parent with the child.  Nothing else appears appropriate
to me.

That's it.  It basically enables object hierarchy, like so:

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

my @sites = $site->webmaster->sites( status => 'active' );
# find all the active sister-ads, the ones that come from the same
advertiser.  Here we utilize child_of & has_many as indicated above.





_______________________________________________
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