[Dbix-class] This feels odd...
Matt S Trout
dbix-class at trout.me.uk
Wed Dec 7 03:16:00 CET 2005
On Tue, Dec 06, 2005 at 04:00:05PM +0000, Nigel Metheringham wrote:
> Given a pair of classes with a belongs_to relationship - say:-
>
> package Parent
> __PACKAGE__->add_columns(qw/id/);
> __PACKAGE__->set_primary_key('id');
>
> package Child
> __PACKAGE__->add_columns(qw/id parent/);
> __PACKAGE__->set_primary_key('id');
> __PACKAGE__->belongs_to(parent => 'Parent');
>
>
> it seems odd to me that given an instance:-
> $parent = Parent->find(1);
>
> that this works:-
> $child = Child->create(parent => $parent);
>
> but to find all the children with a parent I have to do
> $children = Child->search(parent => $parent->id)
>
> ie add an explicit id reference on the end.
>
> I know I could define a children has_many relationship within Parent to
> get this stuff out, but in more complex scenarios you end up with an
> awful lot of them defined....
This works in Class::DBI because of the default stringify-to-PK. Trouble is
this lets you in for being shocked when you have a multi-PK object instead.
DBIC should be smarter here, but I can't think of a good way to be smart
without potentially producing far more confusing behaviour in edge cases.
Any suggestions?
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
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