El 09/01/12 22:09, Miguel Barco escribió:
Thank you, I never would have noticed that the html comments does not affect to the TT/Catlayst logic.

But the problem remains the same, because I want to retrieve some columns from the main table an some from the related one, so I was told to use Prefetch.

What I really need is something as simple as this query (that I can use everywhere):

*SELECT* books.title, contents.content_en
*FROM* books, contents
*WHERE* books.id = 1111
*AND* contents.id = 1111


I suppose that you really mean this (or something similar):

*SELECT* books.title, contents.content_en
*FROM* books, contents
*WHERE* books.id = 1111
*AND* contents.*id_book* = 1111

or better yet:

*SELECT* books.title, contents.content_en
*FROM* books, contents
*WHERE* books.id = 1111
*AND* contents.*id_book = books.id*

(otherwise you would not be joining tables).

Did you get the last part of my email? It shows how to do exactly what you want:

(...)
sub basic_search {
my ($self) = @_;

return $self->search(
{},
{
columns => [qw/ me.title the_content.content_en /],
*join => 'the_content',*
});
}
(...)

I substituted your 'prefetch' by a 'join', which tells DBIC to join the relation (just the table, it does not specify columns). This, coupled with the 'columns' attribute that you specify generates very similar SQL to what you want. And it does not fetch whole rows from the relation, just the columns you specify in the 'columns' attribute.

I also suggest (as some has done, already) to run your app with the shell variable DBIC_TRACE=1, which will show you the generated SQL.

Cheerio :-)
J.

I am be very surprised that I am stuck with it!!

Regards:
Migue

_______________________________________________
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]

Reply via email to