Thank you.
It works, but only when prefetch only 1 table. If i try to do it with both:
my $rs = $c->model('AppModelDB::ClientFemale')->search(undef,
{
join => [qw/
client_family client_male /],
prefetch => [qw/
client_family client_male /]
});
.. the result is:
No such relationship client_male at
/usr/local/share/perl/5.8.8/DBIx/Class/Schema.pm line 945
DBIx::Class::Schema::throw_exception('AppModelDB=HASH(0x927aab4)',
'No such relationship client_male'................etc
I only can use prefetch AppModelDB::ClientFemale -> client_family and
AppModelDB::ClientMale -> client_family. The relationships are
has_many and may_to_many. The "Family" table have
"_PACKAGE__->belongs_to" for both tables.
Regards
2007/12/8, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>
> Здравствуйте, Angel.
>
>
> Вы писали 8 декабря 2007 г., 18:36:55:
>
>
> >
>
> Hi, All. Im new in DBIx::Class and this is my first question here :)
>
> I write catalyst app and use dbic for 3 tables (males,females,family)
> with has_many and may_to_many. All works, but there are too many requests
> to my database when i use this:
>
> my $rs = $c->model('AppModelDB::ClientMale')->search();
>
> while (my $line = $rs->next) {
>
> push @{$families},[ $line->client_family->first->id,
>
> make_family(
>
> $line->first_n,
>
> $line->family_n,
>
> $line->client_female->first->first_n,
>
> $line->client_female->first->family_n
>
> )
>
> ,$line->client_family->first->city
>
> ,$line->client_family->first->zip_code
>
> ,$line->client_family->first->municipality
>
> ,$line->client_family->first->street
>
> ,$line->client_family->first->public_place_type
>
> ,$line->client_family->first->public_place_name
>
> ];
>
> }
>
> }
>
> $c->stash->{families} = $families;
>
>
> I wrote "export DBIC_TRACE=1" for debug and saw alot of screens with
> SELECT requests to MySQL. Plese help me to optimize the code. Every single
> table has around 190 lines.
>
> Thank you
>
>
>
> Use 'join' or 'prefetch' attribute for search. Also see the Cookbook
> http://search.cpan.org/~ash/DBIx-Class-0.08008/lib/DBIx/Class/Manual/Cookbook.pod#JOINS_AND_PREFETCHING<http://search.cpan.org/%7Eash/DBIx-Class-0.08008/lib/DBIx/Class/Manual/Cookbook.pod#JOINS_AND_PREFETCHING>
>
>
> --
>
> С уважением,
>
> dreel mailto:[EMAIL PROTECTED] <[EMAIL PROTECTED]>
>
> _______________________________________________
> 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]
>
_______________________________________________
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]