Hi Moritz! You have to use the rels the same way to prefetch them, without using the many_to_many helper (which I can't see in your code). Imho the ->all is the problem. But why have the MapCategories table at all? Just store the parent or child in your Categories table! Or is it really possible to have multiple parents and childs?
-Alex -----Original Message----- From: Moritz Onken [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 08, 2008 9:48 AM To: DBIx::Class user and developer list Subject: [Dbix-class] DBIC hits DB thoguh using prefetch (repost) Hi, sorry for the repost, but there was no answer to my previous post. I have a table 'categories' which has a many_to_many relationship to itself using a table 'map_categories'. I found out that prefetching a many_to_many rel does not work. So I prefetched the has_many rel to 'map_categories' (parents) and prefetch the belongs_to rel (parent) from 'map_categories' to 'categories' ($rs- >search({},{prefetch => {'parents' => 'parent'}})->all). This does the sql statement I expect but when I call $row->parents->all (or $rs- first->parents->first->parent) on a row of this rs it hits the database again. Although the resultset already contains all rows it needs. Any ideas what I did wrong? cheers, moritz package Schema::Categories; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components("PK::Auto", "Core"); __PACKAGE__->table("categories"); __PACKAGE__->add_columns( "title", { data_type => "character varying", default_value => undef, is_nullable => 1, size => 100, }, "id", { data_type => "integer", is_nullable => 0 }); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many("parents" => 'Schema::MapCategories' => "child"); 1; package Schema::MapCategories; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components("PK::Auto", "Core"); __PACKAGE__->table("map_categories"); __PACKAGE__->add_columns( "child", { data_type => "integer", is_nullable => 0, }, "parent", { data_type => "integer", is_nullable => 0 }); __PACKAGE__->belongs_to("child" => "Schema::Categories", "child"); __PACKAGE__->belongs_to("parent" => "Schema::Categories", "parent"); __PACKAGE__->add_unique_constraint([ qw/child parent/ ]); 1; _______________________________________________ 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/[EMAIL PROTECTED] *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien Handelsgericht Wien, FN 79340b *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* Notice: This e-mail contains information that is confidential and may be privileged. If you are not the intended recipient, please notify the sender and then delete this e-mail immediately. *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* _______________________________________________ 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/[EMAIL PROTECTED]
