Re: How to design such relationship? is it possible at all with caenne?

From: Tomas Jucius (entire..mail.com)
Date: Fri Aug 12 2005 - 16:37:29 EDT

  • Next message: Tomas Jucius: "Re: How to design such relationship? is it possible at all with caenne?"

    One more question..

    How then easily you access discount value form product?

    I dont see easy solution..

    I would like something like.. --- product.getDiscount()..

    How have you accessed these attributes in relational table?

    On 8/12/05, Gentry, Michael (Contractor) <michael_gentr..anniemae.com> wrote:
    > 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:37:30 EDT