I have a parent/child relationship in my schema. I'd like to use very similar code to modify an existing parent as to create a new one. The edit case is easy to find the children:
my $parent = $resultset->find($parent_id);
my @children = $parent->children->all
However, in the new case, something weird happens:
my $parent = $resultset->new_result({});
my @children = $parent->children->all;
I expected to have @children
to be empty, but instead I got back all children, regardless of parent.
I can do something like this (for each related-record accessor, vomit):
sub children {
my $self = shift;
my $res = $self->next::method(@_);
my $parent_no = $self->get_column('parent_no');
defined $parent_no ? $res : $res->search({1 => 2});
}
Please tell me the right way to do this, as the above mustn't be it.
version: 0.08010, because that's what Debian Lenny has (and what our production servers are running)