|
|
|
|
@ -813,7 +813,7 @@ public class StoreCenter { |
|
|
|
|
self._deleteLogs.addOrUpdate(instance: dataLog) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func relationshipStore<T: SyncedStorable>(instance: T, relationship: Relationship) -> Store? { |
|
|
|
|
func relationshipStore<T: Storable>(instance: T, relationship: Relationship) -> Store? { |
|
|
|
|
switch relationship.storeLookup { |
|
|
|
|
case .main: return Store.main |
|
|
|
|
case .child: return self._storeLibrary[instance.stringId] |
|
|
|
|
@ -821,9 +821,21 @@ public class StoreCenter { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func isReferenced<T: SyncedStorable>(instance: T) -> Bool { |
|
|
|
|
func hasDirectReference<T: Storable, S: Storable>(instance: T, relationshipType: S.Type, relationship: Relationship) -> Bool { |
|
|
|
|
if let referenceId = instance[keyPath: relationship.keyPath] as? S.ID, let store = self.relationshipStore(instance: instance, relationship: relationship) { |
|
|
|
|
let instance: S? = store.findById(referenceId) |
|
|
|
|
return instance != nil |
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func isReferenced<T: Storable>(instance: T) -> Bool { |
|
|
|
|
let relationships = T.relationships() |
|
|
|
|
for relationship in relationships { |
|
|
|
|
if self.hasDirectReference(instance: instance, relationshipType: relationship.type, relationship: relationship) { |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let store = self.relationshipStore(instance: instance, relationship: relationship) { |
|
|
|
|
if store.isReferenced(collectionType: relationship.type, type: T.self, id: instance.stringId) { |
|
|
|
|
return true |
|
|
|
|
|