Hi, if you specify relations in the schema files, (assumimg Author table has a foreign key to Book table), like this: <table name="AUTHOR"> .... <foreign-key foreignTable="BOOK"> <reference foreign="BOOK_ID" local="BOOK_ID"/> </foreign-key> </table> Torque will generate save methods in the BaseBook to save authers as well.
For your second question, I don't think it's a bug. I think Torque assumes you are going to do something with the object, otherwise you can always call setModified(false) before call save. Howard On Tue, 14 Sep 2004 18:23:18 +0200, Vitzethum, Daniel <[EMAIL PROTECTED]> wrote: > Hello, > > my name is Daniel. I have just joined the list to ask one > or two related questions: > > I would appreciate if Torque saved an object tree for me - > e.g. I have a Book with two Authors and want to call > > book.addAuthor(a1); > book.addAuthor(a2); > BookPeer.doSave(book); // should insert or update the book and both > authors > > For this purpose, and as it seems that this feature is not > implemented in Torque, I wrote the doSave(Book) method in BookPeer, > like this: > > public static void doSave(Book book) throws TorqueException { > if (matchEinzel.isNew()) { > BookPeer.doInsert(book); > } else { > if (book.isModified()) { > BookPeer.doUpdate(matchEinzel); > } > } > ObjectKey key = book.getPrimaryKey(); > List authors = book.collAuthors; > > // do the same for a List of author objects... > doSaveAuthors(key, authors); > } > > That works quite well, but when I read a simple object from > DB and call the doSave() on it immediately, the object has > "true" as it's modified flag, what results in an (unwanted) > update in the above doSave()-method: > > Book oldBook = BookPeer.retrieveByPK(123); > BookPeer.doSave(oldBook); // performs an Update! > > This can be fixed by overriding a BasePeer's method > row2Object(Record, int, Class) like this - what I don't want > to do for any generated class, as you may have guessed... ;-) > > public static Book row2Object(Record row, int offset, Class cls) > throws TorqueException > { > Book obj = BaseBookPeer.row2Object(row, offset, cls); > obj.setModified(false); > return obj; > } > > So, finally my 2 questions: > - Did I miss a Torque feature that saves an object tree for me? > - Isn't it just wrong that a row being read freshly from DB has > the modified-flag set to true? > > Greetings from Munich, Germany, > > Daniel > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]