[Dbix-class] This feels odd...

Nigel Metheringham nigel.metheringham at dev.intechnology.co.uk
Tue Dec 6 17:00:05 CET 2005


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 one just keeps biting me when I don't get back what I was
expecting :-/

	Nigel.
-- 
[ Nigel Metheringham           Nigel.Metheringham at InTechnology.co.uk ]
[ - Comments in this message are my own and not ITO opinion/policy - ]





More information about the Dbix-class mailing list