Esempio n. 1
0
 public function testFindOneWithDuplicateRelation()
 {
     EssayPeer::doDeleteAll();
     $auth1 = new Author();
     $auth1->setFirstName('John');
     $auth1->save();
     $auth2 = new Author();
     $auth2->setFirstName('Jack');
     $auth2->save();
     $essay = new Essay();
     $essay->setTitle('Foo');
     $essay->setFirstAuthor($auth1->getId());
     $essay->setSecondAuthor($auth2->getId());
     $essay->save();
     AuthorPeer::clearInstancePool();
     EssayPeer::clearInstancePool();
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Essay');
     $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $c->join('Propel\\Tests\\Bookstore\\Essay.AuthorRelatedByFirstAuthor');
     $c->with('AuthorRelatedByFirstAuthor');
     $c->where('Propel\\Tests\\Bookstore\\Essay.Title = ?', 'Foo');
     $essay = $c->findOne();
     $this->assertEquals($essay['Title'], 'Foo', 'Main object is correctly hydrated');
     $firstAuthor = $essay['AuthorRelatedByFirstAuthor'];
     $this->assertEquals($firstAuthor['FirstName'], 'John', 'Related object is correctly hydrated');
     $this->assertFalse(array_key_exists('AuthorRelatedBySecondAuthor', $essay), 'Only related object specified in with() is hydrated');
 }
 public function testFindOneWithDuplicateRelation()
 {
     EssayTableMap::doDeleteAll();
     $auth1 = new Author();
     $auth1->setFirstName('John');
     $auth1->setLastName('Doe');
     $auth1->save();
     $auth2 = new Author();
     $auth2->setFirstName('Jack');
     $auth2->setLastName('Sparrow');
     $auth2->save();
     $essay = new Essay();
     $essay->setTitle('Foo');
     $essay->setFirstAuthor($auth1->getId());
     $essay->setSecondAuthor($auth2->getId());
     $essay->save();
     AuthorTableMap::clearInstancePool();
     EssayTableMap::clearInstancePool();
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Essay');
     $c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
     $c->join('Propel\\Tests\\Bookstore\\Essay.AuthorRelatedByFirstAuthor');
     $c->with('AuthorRelatedByFirstAuthor');
     $c->where('Propel\\Tests\\Bookstore\\Essay.Title = ?', 'Foo');
     $c->limit(1);
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     $essays = $c->find($con);
     foreach ($essays as $essay) {
         break;
     }
     $count = $con->getQueryCount();
     $this->assertEquals($essay->getTitle(), 'Foo', 'Main object is correctly hydrated');
     $firstAuthor = $essay->getAuthorRelatedByFirstAuthor();
     $this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query');
     $this->assertEquals($firstAuthor->getFirstName(), 'John', 'Related object is correctly hydrated');
     $secondAuthor = $essay->getAuthorRelatedBySecondAuthor();
     $this->assertEquals($count + 1, $con->getQueryCount(), 'with() does not hydrate objects not in with');
 }
 public function testFindOneWithDuplicateRelation()
 {
     EssayPeer::doDeleteAll();
     $auth1 = new Author();
     $auth1->setFirstName('John');
     $auth1->save();
     $auth2 = new Author();
     $auth2->setFirstName('Jack');
     $auth2->save();
     $essay = new Essay();
     $essay->setTitle('Foo');
     $essay->setFirstAuthor($auth1->getId());
     $essay->setSecondAuthor($auth2->getId());
     $essay->save();
     AuthorPeer::clearInstancePool();
     EssayPeer::clearInstancePool();
     $c = new ModelCriteria('bookstore', 'Essay');
     $c->join('Essay.AuthorRelatedByFirstAuthor');
     $c->with('AuthorRelatedByFirstAuthor');
     $c->where('Essay.Title = ?', 'Foo');
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $essay = $c->findOne($con);
     $count = $con->getQueryCount();
     $this->assertEquals($essay->getTitle(), 'Foo', 'Main object is correctly hydrated');
     $firstAuthor = $essay->getAuthorRelatedByFirstAuthor();
     $this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query');
     $this->assertEquals($firstAuthor->getFirstName(), 'John', 'Related object is correctly hydrated');
     $secondAuthor = $essay->getAuthorRelatedBySecondAuthor();
     $this->assertEquals($count + 1, $con->getQueryCount(), 'with() does not hydrate objects not in with');
 }