« Return to Thread: Strange behavior with MAToManyRelationDescription

Re: Strange behavior with MAToManyRelationDescription

by Lukas Renggli-2 :: Rate this Message:

Reply to Author | View in Thread

> Ok, I have a Person class and a House class.  Each of these has a
> class side method called #register: that stores the instance in an
> ordered collection of the class side.  Person and House both have full
> descriptions and are capable of displaying themselves, so the
> "manager" class just allows one to make many of these.

Ok, got it.

> This is where I need the custom memento (and tell me if I'm doing this
> wrong):  If you click save that winds up calling "commit" on the
> memento and actually writing the data to the object, but this new
> object wont be registered in the class side collection (and therefor
> will simply cease to exist when this session expires).  So my custom
> memento simply lets everything work as normal and then calls "Person
> register: self model" to get the new object registered.

Sure that's a possibility, but why not use the return value if you are  
using #call: or set an #onAnswer: handler if you are using composition?

So in your manager you have something along:

   house := self call: House new asComponent.
   house ifNotNil: [ House register: house ].

or (in case of composition):

   editor := House new asComponent onAnswer: [ :house |
     house ifNotNil: [ House register: house ].
     editor := nil ]

> The problem happens when "save" returns on Person and you go back to
> the manager page.  You see your nice new Person in the report table as
> expected, but right below is the same Person again!  And if you edit
> either one the changes reflect in both.  And the really hairy thing
> is, even though House is almost exactly the same in every way (I can
> find no relevant difference) it doesn't have this behavior.

Looks like your memento method gets called twice? Why not check if the  
object is already present? Why not use a Set then?

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch


_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki

 « Return to Thread: Strange behavior with MAToManyRelationDescription

LightInTheBox - Buy quality products at wholesale price