Re: Duplicates in to-many relationships

From: Mike Kienenberger (mkienen..mail.com)
Date: Tue Jun 19 2007 - 12:17:24 EDT

  • Next message: yongbl: "Re: Common attributes in the model"

    And note that if you call
    "myFirstObject.addToMyRelation(mySecondObject)", then
    "mySecondObject.setTheObject(myFirstObject)" is also called. It
    doesn't matter which side of the relationship you call. Furthermore,
    if mySecondObject.getTheObject() = myZeroObject beforehand, this
    object will also be removed from the relationship list automatically.
     Ie, everything "just works" out of the box with no extra effort on
    your part.

    On 6/19/07, Mike Kienenberger <mkienen..mail.com> wrote:
    > Unlike Hibernate, the object graph is maintained even before you save.
    >
    > If you use "mySecondObject.setTheObject(myFirstObject)", then the
    > equivalent for "myFirstObject.addToMyRelation(mySecondObject)" is
    > already done for you.
    >
    > This is why you're seeing two copies -- you're effectively calling the
    > addToMyRelationship twice.
    >
    >
    >
    > On 6/19/07, Alexander Lamb (dev) <alam..ac.com> wrote:
    > > Hello list,
    > >
    > > It looks like "myFirstObject.addToMyRelation(mySecondObject)" does
    > > not check if mySecondObject is already in the relationship. Is that
    > > correct?
    > >
    > > If so, here is my problem.
    > >
    > > I know that I can simply do:
    > >
    > > mySecondObject.setTheObject(myFirstObject)
    > >
    > > and then once saved, somehow the reverse relationship will be updated.
    > >
    > > The problem is that I need the reverse relationship before I save.
    > > Therefore I do:
    > >
    > > mySecondObject.setTheObject(myFirstObject)
    > >
    > > and
    > >
    > > myFirstObject.addToMyRelation(mySecondObject)
    > >
    > > In order to have my object graph correct before save.
    > >
    > > Unfortunately, doing this it seems like mySecondObject gets inserted
    > > twice in the List. If I restart the app, everything is fine again.
    > >
    > > Thanks for any hint!
    > >
    > > Alex
    > >
    >



    This archive was generated by hypermail 2.0.0 : Tue Jun 19 2007 - 12:17:48 EDT