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

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

  • Next message: Mike Kienenberger: "mandatory status for ObjRelationship?"

    You see I have gave this only as example.. I don't have product and
    orders.. I have other objects..

    But in relational table I need additional field.. ("discount" in example)..

    There is no other way..

    The thing is that every relation has to have additional one field..

    Maybe I could design this relation in other way.. Maybe somehow with 4
    talbes.. (Have such idea)..

    So I shall think about this.. Really for now don't see any easy solution...

    If you would find - please tell:)..

    On 8/13/05, Gentry, Michael (Contractor) <michael_gentr..anniemae.com> wrote:
    > You can't access the discount easily from the Product. Now that I'm
    > thinking about it a little more, would it make more sense to have the
    > discount on the Order and not the OrderProduct? If the discount applies
    > to all Products in the Order, it would make more sense to put it in the
    > Order. If the discount is for a specific Product in an Order, it makes
    > sense to put it in the OrderProduct.
    >
    > If you do need the discount with the OrderProduct, I'd probaby write
    > some helper methods in your Order subclass so you could say
    > order.getDiscountForProduct(product) or something similar which would
    > find the OrderProduct associated with the passed-in product and return
    > the discount attribute for it. I'd also write a helper methods so you
    > could do order.getProducts(), too. Probably several other useful
    > methods could be added, too. :-)
    >
    > /dev/mrg
    >
    >
    > -----Original Message-----
    > From: Tomas Jucius [mailto:entire..mail.com]
    > Sent: Friday, August 12, 2005 4:37 PM
    > To: cayenne-use..bjectstyle.org; Gentry, Michael (Contractor)
    > Subject: 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 - 17:29:44 EDT