/** * */ public function testObjectInstances_Fkeys() { // Establish a relationship between one employee and account // and then change the employee_id and ensure that the account // is not pulling the old employee. $pub1 = new Publisher(); $pub1->setName('Publisher 1'); $pub1->save(); $pub2 = new Publisher(); $pub2->setName('Publisher 2'); $pub2->save(); $book = new Book(); $book->setTitle("Book Title"); $book->setISBN("1234"); $book->setPublisher($pub1); $book->save(); $this->assertSame($pub1, $book->getPublisher()); // now change values behind the scenes $con = Propel::getServiceContainer()->getConnection(BookstoreEmployeeAccountTableMap::DATABASE_NAME); $con->exec("UPDATE " . BookTableMap::TABLE_NAME . " SET " . " publisher_id = " . $pub2->getId() . " WHERE id = " . $book->getId()); $book2 = BookQuery::create()->findPk($book->getId()); $this->assertSame($book, $book2, "Expected same book object instance"); $this->assertEquals($pub1->getId(), $book->getPublisherId(), "Expected book to have OLD publisher id before reload()"); $book->reload(); $this->assertEquals($pub2->getId(), $book->getPublisherId(), "Expected book to have new publisher id"); $this->assertSame($pub2, $book->getPublisher(), "Expected book to have new publisher object associated."); // Now let's set it back, just to be double sure ... $con->exec("UPDATE " . BookTableMap::TABLE_NAME . " SET " . " publisher_id = " . $pub1->getId() . " WHERE id = " . $book->getId()); $book->reload(); $this->assertEquals($pub1->getId(), $book->getPublisherId(), "Expected book to have old publisher id (again)."); $this->assertSame($pub1, $book->getPublisher(), "Expected book to have old publisher object associated (again)."); }