On 1/28/06 3:30 PM, Mark D. Anderson wrote: > So then we'd have something like: > > my $foo_keyword_rows = MyPackage::FooKeyword->get_foo_keywords(query > => [keyword => 'tra']); > my $matching_foo_rows = [map {$_->foo()} @$foo_keyword_rows]; > > this is dumb because I'm not fetching them with a single request. > (And there is probably shorter syntax too?) > > So then instead I'd need to define a join to do this efficiently? > > Any suggestions?
In your example, it looks like you'll get duplicate Foo objects in some cases (say, for keyword => { like => '%e%' }). I'm not sure if that's intentional. To do it all in one query with no duplicates, I suggest making a "one to many" relationship from Foo to FooKeywords: Foo->meta->relationships ( ... keywords => { type => 'one to many', class => 'FooKeywords', column_map => { id => 'foo_id' }, }, ); Then use a Foo::Manager call like this: $foos = Foo::Manager->get_foos(distinct => 1, require_objects => [ 'keywords' ], query => [ keyword => 'tra' ]); The resulting SQL will be something like this: SELECT DISTINCT t1.id, t1.name, ...rest of the columns from the foo table only... FROM foos t1, foo_keywords t2 WHERE t2.keyword = 'tra' AND t1.id = t2.foo_id If you don't care about or don't expect duplicates, do this instead: $foos = Foo::Manager->get_foos(fetch_only => [ 't1' ], require_objects => [ 'keywords' ], query => [ keyword => 'tra' ]); and the DISTINC keyword will be omitted: SELECT t1.id, t1.name, ...rest of the columns from the foo table only... FROM foos t1, foo_keywords t2 WHERE t2.keyword = 'tra' AND t1.id = t2.foo_id See the Rose::DB::Object::Manager documentation for more information about the "distinct" and "fetch_only" parameters. -John ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object