db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexandru Dovlecel" <alexandru.dovle...@siemens.com>
Subject Save (insert) in cascade
Date Wed, 14 Apr 2004 09:38:56 GMT
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: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message