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
Attribute validation when using merge method #2
Comments
To go a bit further, shouldn't This way the behavior of both methods would be the same (except the fact that one is merging and the other is always inserting), and especially the validation case @zerto is talking about would be called in both cases. Something like the following structure maybe:
|
@zerto, @AliSoftware I see your point, but if In the merge case, we don't want to Consider we insert the following JSON: {
"id": "1699",
"name": "Batman",
"real_name": "Guille Gonzalez",
"powers": [
{
"id": "4",
"name": "Agility"
},
{
"id": "9",
"name": "Insanely Rich"
}
],
"publisher": {
"id": "10",
"name": "DC Comics"
}
} And later we want to fix the real name value by merging this: {
"id": "1699",
"real_name": "Bruce Wayne"
} As the code iterates over the attributes (and relationships) when it reaches the If we want to {
"id": "1699",
"real_name": "Bruce Wayne",
"powers": null
} Maybe this is a matter of personal taste, but for me this is the desired behaviour and something I was missing when using Mantle with Core Data. I also wanted to make two separate code paths for insertion and merge for clarity and performance reasons. I hope shed some light on the merge process. Let me know if you have any other questions. |
Thanks for the answers, you were not too late ^^. I see what you mean, and I agree with it. [
{
"id": "1699",
"name": "Batman",
"real_name": "Guille Gonzalez"
},
{
"id": "1700",
"name": "Superman",
"real_name": "Franck Letellier"
}
] So here everything is check and validated (let's say [
{
"id": "1701",
"name": "Spiderman"
},
{
"id": "1699",
"real_name": "Bruce Wayne"
},
{
"id": "1700",
"real_name": "Clark Kent"
}
] Here, we surely want to use the Then, when we save the context, an error will arise, because I know this is a worst case scenario, and it will probably never appear (the property _ |
Oh! I see. That use case should be easy to implement. I'll find some time tomorrow and submit a pull request. Your feedback will be welcome. |
I think I've been a bit optimistic. This is not as easy to implement as I thought it would be, and would require a major refactoring. The reason is how relationship serialization is implemented. It will take some time to fix it. |
Thanks for your reply. As @zerto was explaining, I believe we understood the problem with For example, I totally agree that, when merging, you have to be careful not to override attributes for which the key is inexistant ( So in either case (merge or import) I believe you may have the same algorithm and the same behavior, including not affecting the attribute when the JSON key is absent ( I believe this approach could, IMHO, simplify your code and its maintenance. |
👍 I will look into it. |
Better late than never. Issue was fixed while 'swiftening' Groot 😄 |
Hi there, |
👍 thx for the heads up |
When using
mergeObjectForEntityName:..., I see that updated entities are not validated if the value is
nil. This happens at line 285 in
GRTJSONSerialization.m`:Now the problem is that when merging, I sometime have new object to insert. But if those new objects have an empty field, they are not validated. So if I have a non-optional attribut in a newly inserted object, and the value is nil, no error is created.
Could there be a way, when using the
merge
method, so that attributes in objects to insert are using the validation process, even if nil?The text was updated successfully, but these errors were encountered: