Hello Artur,

Artur Z wrote:

   Did you defined the foreign key relationship beetwen  Author and
Book in your schema file?
If yes, there should be protected method in BaseAuthorPeer
doSelectJoinBooks() (or something like that). Write this method as
public in AuthorPeer
and than you can use it.

yes, I defined, but there is no such method
torque generated only method BaseBookPeer.doSelectJoinAuthor(...)
as far as I know torque generates only methods for accessing associations
(one), but not collections

There is no one SQL statement that would return you an author tuple and n tuples for his related books.


if you want to access a collection you call author.getBooks(), and it reads
books from db, caches it and returns - it couses perfirmance issues (one db
call for each getXXXs() method)

how to solve it ?
how to query author table to get in return list of authors with ALREADY
INITIALIZED books collections ?

If you take a close look at BaseBookPeer.doSelectJoinAuthor() you will find that this method not only sets the Author for each book but it also builds up the Authors' Book collections. In BaseAuthor.java there is a method called something like addBook(), which is called in the doSelectJoinXXX loop.


The only way you can select all authors and their books in one SQL statement is by selecting all books joined with author (possibly ordered by author). If using Torque that means BaseBookPeer.doSelectJoinAuthor(...).
If you don't want to select all books, just certain authors, you have to pre-set the criteria argument for doSelectJoinXXXX. If you add an OrderBy Author to Criteria, you will get a list of books sorted by authors.


I presume each book has an author, in which case the generated inner join will do you.



I found one solution in
http://www.mail-archive.com/[EMAIL PROTECTED]/msg01712.html
but is not handy and you operate on array of objects, not getXXXs() methods
and collections

This example is pretty much a copy of doSelectJoinXXXX. To translate this to your example, this would produce something like BaseBookPeer.doSelectJoinAuthor(...): read all books pre-fileld with their Authors.



--


Regards/Gru�,

Tarlika Elisabeth Schmitz

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to