File tree Expand file tree Collapse file tree 5 files changed +14
-5
lines changed
CoreDataQueryInterfaceTests Expand file tree Collapse file tree 5 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -170,3 +170,12 @@ extension KeyPathExpressionConvertible {
170170 }
171171}
172172
173+ public protocol Subqueryable : KeyPathExpressionConvertible {
174+ func cdqiSubquery( _ query: ( Self ) -> NSPredicate ) -> ExpressionConvertible
175+ }
176+
177+ extension Subqueryable where Self: EntityAttribute {
178+ public func cdqiSubquery( _ query: ( Self ) -> NSPredicate ) -> ExpressionConvertible {
179+ return subquery ( self , query)
180+ }
181+ }
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ SOFTWARE.
2424
2525import CoreDataQueryInterface
2626
27- class DepartmentAttribute : EntityAttribute {
27+ final class DepartmentAttribute : EntityAttribute , Subqueryable {
2828 private( set) lazy var name : StringAttribute = { StringAttribute ( key: " name " , parent: self ) } ( )
2929 private( set) lazy var employees : EmployeeAttribute = { EmployeeAttribute ( key: " employees " , parent: self ) } ( )
3030}
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ SOFTWARE.
2424
2525import CoreDataQueryInterface
2626
27- class EmployeeAttribute : EntityAttribute {
27+ final class EmployeeAttribute : EntityAttribute , Subqueryable {
2828 private( set) lazy var firstName : StringAttribute = { StringAttribute ( key: " firstName " , parent: self ) } ( )
2929 private( set) lazy var lastName : StringAttribute = { StringAttribute ( key: " lastName " , parent: self ) } ( )
3030 private( set) lazy var nickName : StringAttribute = { StringAttribute ( key: " nickName " , parent: self ) } ( )
Original file line number Diff line number Diff line change @@ -88,8 +88,8 @@ class FilterTests : BaseTestCase {
8888
8989 func testNumberOfDepartmentsWithEmployeesWhoseLastNamesStartWithSUsingSubquery( ) {
9090 let departmentCount = try ! managedObjectContext. from ( Department . self) . filter { department in
91- subquery ( department. employees) { ( employee : EmployeeAttribute ) in
92- some ( employee . lastName. cdqiBeginsWith ( " S " , options: . caseInsensitive) )
91+ department. employees. cdqiSubquery {
92+ some ( $0 . lastName. cdqiBeginsWith ( " S " , options: . caseInsensitive) )
9393 } . cdqiCount ( ) > 0
9494 } . count ( )
9595 XCTAssertEqual ( departmentCount, 2 )
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ SOFTWARE.
2424
2525import CoreDataQueryInterface
2626
27- class TestEntityAttribute : EntityAttribute {
27+ final class TestEntityAttribute : EntityAttribute , Subqueryable {
2828 private( set) lazy var binary : DataAttribute = { DataAttribute ( key: " binary " , parent: self ) } ( )
2929 private( set) lazy var boolean : BoolAttribute = { BoolAttribute ( key: " boolean " , parent: self ) } ( )
3030 private( set) lazy var date : DateAttribute = { DateAttribute ( key: " date " , parent: self ) } ( )
You can’t perform that action at this time.
0 commit comments