Hi,
As far as I understand, the second X.save() is not
needed. But I too agree with you and feel it would be nice if we can do the X.save()
after all the X.addY().
Correct me if I'm wrong, but I assume one can't do
X.addY(y1) without calling X.save().
~Sarav
-----Original Message-----
From: "Alexandru Dovlecel" <[EMAIL PROTECTED]>
To: "'Apache Torque Users List'" <[EMAIL PROTECTED]>
Date: Wed, 14 Apr 2004 12:38:56 +0300
Subject: Save (insert) in cascade
Hi all,
Another question to ask&propose a possible solution.
I have X with a ToMany Y.
When I want to create an X with (let's say) 3 Ys, I have to do the
following:
con = Transaction.begin( mydb ) ;
X = new X() ;
X.save() ;
y1 = new Y() ;
X.addY( y1 ) ;
y2 = new Y() ;
X.addY( y2 ) ;
y3 = new Y() ;
X.addY( y3 ) ;
X.save() ;
// or y1.save, y2.save, y3.save...
It is quite complicated... I think. It would be nice and elegant if doing
like this:
x = new X() ;
y1 = new Y() ;
x.addY( y1 ) ;
y2 = new Y() ;
x.addY( y2) ;
x.save() ;
Now, if X has an autoincrement PK, this does not work. But we could change
the Object.vm in order to make it work. In each for (relation)
if the X is new, then
Y.setIdX( this.getId() ) ;
Y.save() ;
The same solution could be implemented for ToOne relations.
As a result, this change will ease the use of torque (I think), but I don't
know what problems might arrise because of those changes. And also it
reduces the number of queries to the DBServer (by one): when doing the first
addY( y1 ), there is a query to DB in order to retrieve the Ys from the
database.
What is your oppinion? Has somebody tried this? And if so, did they hit any
wall when doing this?
Regards,
Alex
---------------------------------------------------------------------
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]