On 10/01/2012 8:09 AM, Miguel Barco wrote:
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.
Which is fine as this is basically an optimisation to avoid going back to the database engine to call rows from the related table entry.

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

Which is more or less exactly what prefetch is doing for you. Set DBIC_TRACE=1 on the command line before starting you app to see what is happening.

But what you are basically missing is that your "contents" table is the related table. Therefore for each "book" there are *many* "contents". So not only are you iterating through the books, you need to iterate through the "contents" as well otherwise of course you are just accessing the first line. To see the others you call the next one, and so on.

So basically you need to stop thinking in terms of the raw sql results and start thinking in terms of the objects that are represented. A "book" with many "contents" Which is what an ORM is for.

Neil


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

Regards:
Migue


------------------------------------------------------------------------
*De:* Jorge Gonzalez <[email protected]>
*Para:* [email protected]
*Enviado:* lunes 9 de enero de 2012 10:49
*Asunto:* Re: [Dbix-class] I get only one in a one to one

You have commented out the line where you get content_en from the CONTENTS table, but you have done so _in HTML_. The template engine is running your template, including your HTML comment, and is getting the content_en field, just to put it in an HTML comment.

If you want to avoid the TT engine calling the relationship you must comment the call _inside_ the TT code, i.e.:

(...)
[% FOREACH book IN books -%]
<tr>
<td>[% book.title %]</td>
*<td>[% # book.the_content.content_en %]</td>
*
</tr>
[% END -%]
(...)

And something more: if you just want a column from a relation, do a join, not a prefetch:


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

Reply via email to