Originally created by @tosbaha on GitHub (May 4, 2018).
I am using ImportUniqueObjects extension to import data from the server. If the Store is empty import works but if there is a previous data, following error comes
I think the issue is that the moment this line is executed,
self.detail=NSOrderedSet(array:details)
the old KargoDetailCD instances get their KargoDetailCD.parent set to nil. You probably have a "required" constraint for the KargoDetailCD.parent relation.
Either you remove this requirement, or you delete the old details before you assign new ones. I would recommend the latter so your sqlite file don't get polluted with orphaned records.
@JohnEstropia commented on GitHub (May 5, 2018):
@tosbaha If I'm interpreting your error message correctly,
> NSValidationErrorObject=<KargoDetailCD: 0x600000289fb0>
> ...
> NSValidationErrorKey=parent
I think the issue is that the moment this line is executed,
```swift
self.detail = NSOrderedSet(array: details)
```
the old `KargoDetailCD` instances get their `KargoDetailCD.parent` set to `nil`. You probably have a "required" constraint for the `KargoDetailCD.parent` relation.
Either you remove this requirement, or you delete the old details before you assign new ones. I would recommend the latter so your sqlite file don't get polluted with orphaned records.
PS:
It is not related to this question directly, but is there a way to have a Uniqueness by using multiple fields. Because for this user case, I don't have any ID to differentiate. Something like Hashable protocol maybe?
@tosbaha commented on GitHub (May 5, 2018):
Thanks a lot! I really appreciate your dedication to this project. I added below code and error is gone.
```swift
if let deletable = self.detail.array as? [KargoDetailCD] {
transaction.delete(deletable)
}
```
PS:
It is not related to this question directly, but is there a way to have a Uniqueness by using multiple fields. Because for this user case, I don't have any ID to differentiate. Something like Hashable protocol maybe?
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @tosbaha on GitHub (May 4, 2018).
I am using ImportUniqueObjects extension to import data from the server. If the Store is empty import works but if there is a previous data, following error comes
I know code 1560 is validation error but why it works in the first time but not the second time puzzles me. Error code also shows that parent is nil.
Here is the relevant models
@JohnEstropia commented on GitHub (May 5, 2018):
@tosbaha If I'm interpreting your error message correctly,
I think the issue is that the moment this line is executed,
the old
KargoDetailCDinstances get theirKargoDetailCD.parentset tonil. You probably have a "required" constraint for theKargoDetailCD.parentrelation.Either you remove this requirement, or you delete the old details before you assign new ones. I would recommend the latter so your sqlite file don't get polluted with orphaned records.
@tosbaha commented on GitHub (May 5, 2018):
Thanks a lot! I really appreciate your dedication to this project. I added below code and error is gone.
PS:
It is not related to this question directly, but is there a way to have a Uniqueness by using multiple fields. Because for this user case, I don't have any ID to differentiate. Something like Hashable protocol maybe?