Originally created by @kevinrenskers on GitHub (Oct 25, 2017).
When I am importing objects from my remote server, I have something like this:
// Import objects
let objects = try transaction.importUniqueObjects(Into<T>(), sourceArray: source)
// Delete objects not part of the new collection
transaction.deleteAll(From<T>(), Where("NOT(self in %@)", objects))
So first I import the unique objects, then delete everything that wasn't part of this new collection. This used to work great! However now that I refactored to use CoreStoreObject, it's always removing all objects. Apparently this Where clause does not work properly when used with CoreStoreObject.
Is there a way to get the same functionality working with CoreStoreObject?
Originally created by @kevinrenskers on GitHub (Oct 25, 2017).
When I am importing objects from my remote server, I have something like this:
```
// Import objects
let objects = try transaction.importUniqueObjects(Into<T>(), sourceArray: source)
// Delete objects not part of the new collection
transaction.deleteAll(From<T>(), Where("NOT(self in %@)", objects))
```
So first I import the unique objects, then delete everything that wasn't part of this new collection. This used to work great! However now that I refactored to use CoreStoreObject, it's always removing _all_ objects. Apparently this Where clause does not work properly when used with CoreStoreObject.
Is there a way to get the same functionality working with CoreStoreObject?
@kevinrenskers commented on GitHub (Oct 25, 2017):
Would I have to fetch all primary keys? I don't use a consistent property name for that though (like giftId, userId, etc) so I don't know how I would make that work?
@kevinrenskers commented on GitHub (Oct 25, 2017):
Would I have to fetch all primary keys? I don't use a consistent property name for that though (like giftId, userId, etc) so I don't know how I would make that work?
@kevinrenskers commented on GitHub (Oct 25, 2017):
Solved my own problem:
// Import objects
let objects = try transaction.importUniqueObjects(Into<T>(), sourceArray: source)
if !objects.isEmpty {
// Delete objects not part of the new collection
let ids = objects.map { $0.uniqueIDValue }
transaction.deleteAll(From<T>(), Where("NOT(%K in %@)", type.uniqueIDKeyPath, ids))
}
@kevinrenskers commented on GitHub (Oct 25, 2017):
Solved my own problem:
```
// Import objects
let objects = try transaction.importUniqueObjects(Into<T>(), sourceArray: source)
if !objects.isEmpty {
// Delete objects not part of the new collection
let ids = objects.map { $0.uniqueIDValue }
transaction.deleteAll(From<T>(), Where("NOT(%K in %@)", type.uniqueIDKeyPath, ids))
}
```
@kevinrenskers You may also want to use the ! operator on Where:
transaction.deleteAll(From<T>(),!Where("SELF in %@",ids))
I recommend that you go through the README first. It's long but you'll find a lot of convenient way for common tasks.
@JohnEstropia commented on GitHub (Oct 26, 2017):
@kevinrenskers You may also want to use the `!` operator on `Where`:
```swift
transaction.deleteAll(From<T>(), !Where("SELF in %@", ids))
```
I recommend that you go through the README first. It's long but you'll find a lot of convenient way for common tasks.
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 @kevinrenskers on GitHub (Oct 25, 2017).
When I am importing objects from my remote server, I have something like this:
So first I import the unique objects, then delete everything that wasn't part of this new collection. This used to work great! However now that I refactored to use CoreStoreObject, it's always removing all objects. Apparently this Where clause does not work properly when used with CoreStoreObject.
Is there a way to get the same functionality working with CoreStoreObject?
@kevinrenskers commented on GitHub (Oct 25, 2017):
Would I have to fetch all primary keys? I don't use a consistent property name for that though (like giftId, userId, etc) so I don't know how I would make that work?
@kevinrenskers commented on GitHub (Oct 25, 2017):
Solved my own problem:
@JohnEstropia commented on GitHub (Oct 26, 2017):
@kevinrenskers You may also want to use the
!operator onWhere:I recommend that you go through the README first. It's long but you'll find a lot of convenient way for common tasks.