[Dbix-class] Towards 0.03: Relationship helpers done with
skeleton docs
Matt S Trout
dbix-class at trout.me.uk
Sun Sep 18 20:13:49 CEST 2005
On Sat, Sep 17, 2005 at 06:17:05PM +0100, Matt S Trout wrote:
> I've just integrated and committed the quote test from Simon Elliot and
> the HasOne relationship and test rework from abraxxa.
I stared at it for a bit and realised abraxxa's has_one was actually
belongs_to (at least according to the AR API, which makes reasonable sense)
so I renamed that, yanked the non-CDBI-specific parts out of might_have and
has_many, and created a has_one that's basically might_have but with a
straight rather than a LEFT join. POD is the following -
All convenience methods take a signature of the following
format -
__PACKAGE__>method_name('relname', 'Foreign::Class', $join?, $attrs?);
has_one
my $f_obj = $obj->relname;
Creates a one-one relationship with another class;
defaults to PK-PK for the join condition unless a con
dition is specified.
might_have
my $f_obj = $obj->relname;
Creates an optional one-one relationship with another
class; defaults to PK-PK for the join condition unless
a condition is specified.
has_many
my @f_obj = $obj->relname($cond?, $attrs?);
my $f_result_set = $obj->relname($cond?, $attrs?);
$obj->add_to_relname(\%col_data);
Creates a one-many relationship with another class;
belongs_to
my $f_obj = $obj->relname;
$obj->relname($new_f_obj);
Creates a relationship where we store the foreign
class' PK; if $join is a column name instead of a con
dition that is assumed to be the FK, if not has_many
assumes the FK is the relname is that is a column on
the current class.
--
Matt S Trout Specialists in perl consulting, web development, and
Technical Director UNIX/Linux systems architecture and automation. Mail
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Dbix-class
mailing list