Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
This repository was archived by the owner on Apr 17, 2018. It is now read-only.

Inconsistent views when creating and accessing associations #82

Open
@solnic

Description

@solnic

Just getting started with DM and I apologise if I have misunderstood the scope of the identity map semantics and intended behaviour of associations.

With a basic join model, accessing the association from the "has side" before the join model is saved leaves the association/collection empty even after the save occurs.

See pastie for details http://www.pastie.org/222592

Not sure if this is intended, but it seems to break the identity map / object equivalence illusion as you can obtain another instance of the object from the model after saving the join table and the association collection on that instance now works. Even though obj1 == obj2 => true, the instances behave quite differently. Is this intended ?

Also, from the join table (ie the belongs_to side) the association does indeed exist (even before the save). It seems inconsistent/unexpected that the association is only visible from one side, and only visible from the other side after saving ... and then only if you haven't previously attempted to access the association.

The identity map seems to only actually apply to the key field(s) so while the object identities are the same, the actual object instances are different and their contents are thus independent and can actually be quite different, eg:

obj1 = Model.first
obj2 = Model.first
obj1 == obj2
=> true
ob1.name = "Ben"
obj2.name = "Joe"
obj1 == obj2
=> true
obj1.name == obj2.name
=> false

Is this intended ? Documentation may need to cover this unless I missed it somewhere.

Q: In light of transactions, would/could the approach being used/planned only create one actual object instance for each database identity referenced within a transaction context ? Changes to an object/object-graph would remain isolated to that transaction context until the transaction commits. I realise this is probably a can of worms ... but :) extending the database notion of transaction isolation to the in-memory object model would be really cool especially for maintaining object graph consistency in a multi-threaded server.


Created by Hax - 2010-02-04 07:29:53 UTC

Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/418

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions