Field.Relationship propertyWrapper

This commit is contained in:
John Estropia
2020-01-20 17:13:01 +09:00
parent bcc2d9def3
commit 92ad895044
12 changed files with 881 additions and 304 deletions

View File

@@ -235,6 +235,20 @@ public func ~ <O: NSManagedObject, D: NSManagedObject, T, C: AllowedObjectiveCTo
// MARK: - ~ where D: CoreStoreObject
/**
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
```
let owner = dataStack.fetchOne(From<Pet>().where((\.$master ~ \.$name) == "John"))
```
*/
public func ~ <O: CoreStoreObject, D: FieldRelationshipToOneType, K: KeyPathStringConvertible>(_ lhs: KeyPath<O, FieldContainer<O>.Relationship<D>>, _ rhs: KeyPath<D.DestinationObjectType, K>) -> Where<O>.Expression<Where<O>.SingleTarget, K.DestinationValueType> where K.ObjectType == D.DestinationObjectType {
return .init(
O.meta[keyPath: lhs].cs_keyPathString,
D.DestinationObjectType.meta[keyPath: rhs].cs_keyPathString
)
}
/**
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
```
@@ -277,6 +291,20 @@ public func ~ <O: CoreStoreObject, D: CoreStoreObject, T, K: KeyPathStringConver
)
}
/**
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
```
let happyPets = dataStack.fetchAll(From<Pet>().where((\.$master ~ \.$pets).count() > 1))
```
*/
public func ~ <O: CoreStoreObject, D: FieldRelationshipToOneType, K: ToManyRelationshipKeyPathStringConvertible>(_ lhs: KeyPath<O, FieldContainer<O>.Relationship<D>>, _ rhs: KeyPath<D.DestinationObjectType, K>) -> Where<O>.Expression<Where<O>.CollectionTarget, K.DestinationValueType> where K.ObjectType == D.DestinationObjectType {
return .init(
O.meta[keyPath: lhs].cs_keyPathString,
D.DestinationObjectType.meta[keyPath: rhs].cs_keyPathString
)
}
/**
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
```