Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for cyclic relationships in Manage #889

Closed
nirinchev opened this issue Oct 25, 2016 · 3 comments
Closed

Add support for cyclic relationships in Manage #889

nirinchev opened this issue Oct 25, 2016 · 3 comments

Comments

@nirinchev
Copy link
Member

nirinchev commented Oct 25, 2016

We don't support cyclic relationships when the same object is not represented by the same reference e.g.

var person = new Person { Name = "Peter", Id = 1 };
person.Dog = new Dog();
person.Dog.Owner = new Person { Id = 1 };

Ideally, Manage should figure out that we've already persisted Person(1) and merge the properties instead of overwriting them each time it sees a new instance. Obviously, this raises the question what is the correct behavior when dealing with the following object:

var person = new Person { Name = "Peter", Id = 1 };
person.Dog = new Dog();
person.Dog.Owner = new Person { Name = "John", Id = 1 };
@nirinchev nirinchev added this to the v1.0 milestone Oct 25, 2016
@bdash
Copy link
Contributor

bdash commented Oct 25, 2016

Those don't look like cyclic relationships to me. If they were cyclic the Owner field would refer back to the original Person, rather than a different one. I think I'd expect both examples to throw if Id is marked as a primary key since you're attempt to insert two objects with the same value for the primary key property. If Id isn't a primary key I'd expect the original person and the dog's owner to end up being two separate objects that happen to have the same value for the Id field. I'm not sure how any other interpretation would make sense.

@nirinchev
Copy link
Member Author

They are not cyclic in terms of object references, but they are in terms of data. We already support the object reference scenario:

var person = new Person { Name = "Peter", Id = 1 };
person.Dog = new Dog();
person.Dog.Owner = person;

That works just fine, because when we get to managing the owner, we can see that it's already been managed.

Also, this is more of a ManageOrUpdate scenario (I'll update the issue text to reflect that) that is handled fine in javascript and cocoa, but not in .NET. The original scenario that @fealebenpae described when discussing this is having a json response that we want to deserialize and persist, where objects are serialized partially after the first appearance, e.g.:

"name":"peter",
"id":1,
"dog": {
    "name":"Rex",
    "owner": {
        "id":1
    }
}

This will work just fine with Javascript because the second time we try to Manage the person with id = 1, they'll have no properties to persist and thus will not overwrite whatever was set initially. With .NET, however, after the object is deserialized into a c# class, we have no way of knowing which properties were originally present in the json response, so we'll have to overwrite all of them.

@sync-by-unito
Copy link

sync-by-unito bot commented Aug 14, 2023

➤ nirinchev commented:

Closing since it doesn't appear to have been a real-world issue.

@sync-by-unito sync-by-unito bot closed this as completed Aug 14, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants