Yes, it's possible.
You have Order <->> OrderProduct <<-> Product
Assuming you already have an "order" and an "product" in memory (in the
same DataContext):
DataContext dc = order.getDataContext();
OrderProduct orderProduct =
(OrderProduct) dc.createAndRegisterNewObject(OrderProduct.class);
orderProduct.setOrder(order);
orderProduct.setProduct(product);
orderProduct.setDiscount(discount);
dc.commitChanges();
Be sure to setup your Cayenne model with the appropriate
relationships/attributes and it should work fine (it has for me before).
Of course, make sure your discount allows nulls so you can omit it if
not present (or set it to zero/etc).
/dev/mrg
-----Original Message-----
From: Tomas Jucius [mailto:entire..mail.com]
Sent: Friday, August 12, 2005 4:14 PM
To: cayenne-use..bjectstyle.org
Subject: How to design such relationship? is it possible at all with
caenne?
I have many-to-many relationship with additional field "discount" in
relational table..
This is scheme:
Table Order fields: order_id, .......other fields....
Table OrderProduct: order_id, product_id, discount
Table Product: product_id, ......other fields......
When there is no "discount" when everything is fine..
How to design such relationship with cayenne.. Is it possible..
And if possible, when how I would have to add new product to orders
(how about discount value)?
This archive was generated by hypermail 2.0.0 : Fri Aug 12 2005 - 16:23:29 EDT