Skip to content

Commit 31490fd

Browse files
committed
Subqueryable
1 parent 8c35817 commit 31490fd

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

CoreDataQueryInterface/Protocols.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

CoreDataQueryInterfaceTests/DepartmentAttribute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424

2525
import 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
}

CoreDataQueryInterfaceTests/EmployeeAttribute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424

2525
import 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) }()

CoreDataQueryInterfaceTests/FilterTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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)

CoreDataQueryInterfaceTests/TestEntityAttribute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424

2525
import 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) }()

0 commit comments

Comments
 (0)