db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <Fisc...@seitenbau.net>
Subject RE: Saving associated objects
Date Wed, 08 Dec 2004 14:11:33 GMT




Hi Daniel,

I am not sure if I understand the question. Let me pose the question in my
own words:
You have a 1:n relation. If you save an object on the "1" side, the related
objects on the "n" side get saved.
If you are on the "n" side, why is the "1" side not saved ?

The "1" side is the side where no foreign key is defined (just the primary
key of the objects)
The "n" side is the side where objects hold an additional foreign key which
references the primary key on the "1" side.
I would think this behaviour is logical, as otherwise there might be more
objects saved as you want (all the other objects which are related to the
"1" side)

If you have a real 1:1 behaviour, you can put the foreign key on the other
side, then you can "save through" from the other side. As far as I know
(which is not very far in this area), there is no way how you can define a
"real" 1:1 relation, so you cannot expect to get saves on both sides
automatically.

If you do not have too many  relations of this sort, a solution would be to
override the save(..) methods in the persistent Objects.

   Thomas


"Vitzethum, Daniel" <Daniel.Vitzethum@gigatronik.com> schrieb am 08.12.2004
14:39:25:

> Hello list,
>
> one more question:
>
> when saving, Torque's save methods just consider the associated
> collections for saving, but not the single objects associated
> by foreign key.
>
> Some code:
> ---snip---
> public void save(Connection con) throws TorqueException {
>   (...)
>   if (collSomeObjects != null)
>   {
>     for (int i = 0; i < collSomeObjects.size(); i++)
>     {
>       ((SomeObject) collSomeObjects.get(i)).save(con);
>     }
>   }
>   (...)
> }
> ---snip---
>
> But where is
> ---
>   if (aOtherObject != null) {
>     aOtherObject.save(son);
>   }
> ---
>
> Why that, and can I influence this behavior?
>
>
> Daniel
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


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