public function testAlias()
 {
     $this->assertEquals('foo.ID', BookPeer::alias('foo', BookPeer::ID), 'alias() returns a column name using the table alias');
     $this->assertEquals('book.ID', BookPeer::alias('book', BookPeer::ID), 'alias() returns a column name using the table alias');
     $this->assertEquals('foo.COVER_IMAGE', MediaPeer::alias('foo', MediaPeer::COVER_IMAGE), 'alias() also works for lazy-loaded columns');
     $this->assertEquals('foo.SUBTITLE', EssayPeer::alias('foo', EssayPeer::SUBTITLE), 'alias() also works for columns with custom phpName');
 }
 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->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $c->join('Essay.AuthorRelatedByFirstAuthor');
     $c->with('AuthorRelatedByFirstAuthor');
     $c->where('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()
 {
     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');
 }
 public function testFindOneWithEmptyDuplicateRelation()
 {
     EssayPeer::doDeleteAll();
     $author = new Author();
     $author->setFirstName('Piet');
     $author->setLastName('Sous');
     $author->save();
     AuthorPeer::clearInstancePool();
     EssayPeer::clearInstancePool();
     $query = AuthorQuery::create()->useEssayRelatedByFirstAuthorQuery()->orderByTitle()->endUse()->with('EssayRelatedByFirstAuthor');
     $author = $query->findOne();
     // should not throw a notice
     $this->assertTrue(true);
 }