mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-24 02:11:12 +01:00
Field.Relationship propertyWrapper
This commit is contained in:
@@ -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
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user