public function testAssociateRelationHasMany() { $author = new Author($this->conn, ['id' => 1]); $author->setStored(); $book1 = new Book($this->conn, ['authors_id' => 3]); $book1->setStored(); $book2 = new Book($this->conn, ['authors_id' => 5]); $book2->setStored(); $book3 = new Book($this->conn, ['authors_id' => 1]); $book3->setStored(); $this->assertSame(1, $author->id); $this->assertSame(3, $book1->authors_id); $this->assertSame(5, $book2->authors_id); $this->assertSame(1, $book3->authors_id); $author->associateRelation('books', new EntityCollection([$book1, $book2, $book3])); $this->assertSame(1, $author->id); $this->assertSame(1, $book1->authors_id); $this->assertSame(1, $book2->authors_id); $this->assertSame(1, $book3->authors_id); $this->assertFalse($author->isModified()); $this->assertTrue($book1->isModified()); $this->assertTrue($book2->isModified()); $this->assertFalse($book3->isModified()); }