If I was developing the schema, in addition to the relation you show, in Result::Bar I'd have:
__PACKAGE__->belongs_to('foo', 'MyApp::Schema::Result::Foo', { ... }); Then search for all the bars with a particular foo (you use the name of the relation, not the table) property: foreach my $r_bar ($schema->resultset('Bar')->search({ 'foo.x' => 'Baz' })) { $r_bar->some_method; } > On 18 Apr 2017, at 16:59, Vladimir Melnik <v.mel...@uplink.ua> wrote: > > Hello, > > And one more question, if anyone doesn't mind. :-) > > Is there an elegant way to apply a Result's method to the whole ResultSet? > > In other words, here's what I have to do: > # MyApp::Schema::Result::Foo->has_many('bars', > 'MyApp::Schema::Result::Bar', { ... }); > my $rs_foo = $schema->resultset('Foo')->search({ ... }); > foreach my $r_foo ($rs_foo->all) { > foreach my $r_bar ($r_foo->bars->all) { > $r_bar->some_method; > } > } > > ...or something like like that: > # MyApp::Schema::Result::Foo->has_many('bars', > 'MyApp::Schema::Result::Bar', { ... }); > my $rs_foo = $schema->resultset('Foo')->search({ ... }); > foreach my $r_bar (map { $_->bars->all } $rs_foo->all) { > $r_bar->some_method; > } > > ...and here's what I would like to do: > # MyApp::Schema::Result::Foo->has_many('bars', > 'MyApp::Schema::Result::Bar', { ... }); > my $rs_foo = $schema->resultset('Foo')->search({ ... }); > foreach my $r_bar ($rs_foo->bars->all) { > $r_bar->some_method; > } > > Do I have to add the "bars" method to the MyApp::Schema::ResultSet::Foo class > manually? > > Thanks in advance! > > -- > V.Melnik -- The Wellcome Trust Sanger Institute is operated by Genome Research Limited, a charity registered in England with number 1021457 and a company registered in England with number 2742969, whose registered office is 215 Euston Road, London, NW1 2BE. _______________________________________________ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk