             stack.perform(
                 asynchronous: { (transaction) in
                     
-                    let p1 = Bird.where({ $0.species == "Sparrow" })
-                    XCTAssertEqual(p1.predicate, Where("%K == %@", "species", "Sparrow").predicate)
+                    let p1 = Animal.where({ $0.species == "Sparrow" })
+                    XCTAssertEqual(p1.predicate, NSPredicate(format: "%K == %@", "species", "Sparrow"))
                     
-                    let bird = transaction.fetchOne(
-                        From<Bird>(),
-                        Tweak({ $0.includesSubentities = false })
-                    )
+                    let bird = transaction.fetchOne(From<Animal>(), p1)
                     XCTAssertNotNil(bird)
                     XCTAssertEqual(bird!.species*, "Sparrow")
                     
-                    let p2 = Mascot.where({ $0.nickname == "Riko" })
-                    XCTAssertEqual(p2.predicate, Where("%K == %@", "nickname", "Riko").predicate)
+                    let p2 = Dog.where({ $0.nickname == "Spot" })
+                    XCTAssertEqual(p2.predicate, NSPredicate(format: "%K == %@", "nickname", "Spot"))
                     
-                    let mascot = transaction.fetchOne(From<Mascot>())
-                    XCTAssertNotNil(mascot)
-                    XCTAssertEqual(mascot!.nickname*, "Riko")
-                    XCTAssertEqual(mascot!.species*, "Swift3")
+                    let dog = transaction.fetchOne(From<Dog>(), p2)
+                    XCTAssertNotNil(dog)
+                    XCTAssertEqual(dog!.nickname*, "Spot")
+                    XCTAssertEqual(dog!.species*, "Dog")
                     
-                    let cat = transaction.fetchOne(From<Cat>())
-                    XCTAssertEqual(cat?.toy.value, mascot)
+                    let person = transaction.fetchOne(From<Person>())
+                    XCTAssertNotNil(person)
+                    XCTAssertEqual(person!.pet.value, dog)
                     
-                    let p3 = Mascot.where({ $0.year == 2016 })
-                    XCTAssertEqual(p3.predicate, Where("%K == %@", "year", 2016).predicate)
+                    let p3 = Dog.where({ $0.age == 10 })
+                    XCTAssertEqual(p3.predicate, NSPredicate(format: "%K == %d", "age", 10))
                 },
                 success: {
             

@testable import CoreStore


class Bird: ManagedObject {
    
    let species = Attribute.Required<String>("species", default: "Swift")
    let enemy = Relationship.ToOne<Cat>("enemy", inverse: { $0.toy })
}
class Mascot: Bird {
    
    let nickname = Attribute.Optional<String>("nickname")
    let year = Attribute.Required<Int>("year", default: 2016)
}
class Cat: ManagedObject {
    
    let name = Attribute.Required<String>("name")
    let toy = Relationship.ToOne<Bird>("toy")
}



            dynamicModel: ObjectModel(
                version: "V1",
                entities: [
                    Entity<Animal>("Animal"),
                    Entity<Dog>("Dog"),
                    Entity<Person>("Person")
                ]
            )
        )
        self.prepareStack(dataStack, configurations: [nil]) { (stack) in
            
            let k1 = Animal.keyPath({ $0.species })
            XCTAssertEqual(k1, "species")
            
            let k2 = Dog.keyPath({ $0.species })
            XCTAssertEqual(k2, "species")
            
            let k3 = Dog.keyPath({ $0.nickname })
            XCTAssertEqual(k3, "nickname")
            
            let expectation = self.expectation(description: "done")
            stack.perform(
                asynchronous: { (transaction) in
                    
                    let animal = transaction.create(Into<Animal>())
                    XCTAssertEqual(animal.species*, "Swift")
                    XCTAssertTrue(type(of: animal.species*) == String.self)
                    
                    animal.species .= "Sparrow"
                    XCTAssertEqual(animal.species*, "Sparrow")
                    
                    let dog = transaction.create(Into<Dog>())
                    XCTAssertEqual(dog.species*, "Swift")
                    XCTAssertEqual(dog.nickname*, nil)
                    
                    dog.species .= "Dog"
                    XCTAssertEqual(dog.species*, "Dog")
                    
                    dog.nickname .= "Spot"
                    XCTAssertEqual(dog.nickname*, "Spot")
                    
                    let person = transaction.create(Into<Person>())
                    XCTAssertNil(person.pet.value)
                    
                    person.pet .= dog
                    XCTAssertEqual(person.pet.value, dog)
                    XCTAssertEqual(person.pet.value?.master.value, person)
                    XCTAssertEqual(dog.master.value, person)
                    XCTAssertEqual(dog.master.value?.pet.value, dog)
                },
                success: {
                    
