public function testAlias()
 {
     $this->assertEquals('foo.ID', BookTableMap::alias('foo', BookTableMap::ID), 'alias() returns a column name using the table alias');
     $this->assertEquals('book.ID', BookTableMap::alias('book', BookTableMap::ID), 'alias() returns a column name using the table alias');
     $this->assertEquals('foo.COVER_IMAGE', MediaTableMap::alias('foo', MediaTableMap::COVER_IMAGE), 'alias() also works for lazy-loaded columns');
     $this->assertEquals('foo.SUBTITLE', EssayTableMap::alias('foo', EssayTableMap::SUBTITLE), 'alias() also works for columns with custom phpName');
 }
 public function testAlias()
 {
     $this->assertEquals('foo.id', BookTableMap::alias('foo', BookTableMap::COL_ID), 'alias() returns a column name using the table alias');
     $this->assertEquals('book.id', BookTableMap::alias('book', BookTableMap::COL_ID), 'alias() returns a column name using the table alias');
     $this->assertEquals('foo.cover_image', MediaTableMap::alias('foo', MediaTableMap::COL_COVER_IMAGE), 'alias() also works for lazy-loaded columns');
     $this->assertEquals('foo.subtitle', EssayTableMap::alias('foo', EssayTableMap::COL_SUBTITLE), 'alias() also works for columns with custom phpName');
 }
 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');
 }
Пример #4
0
 public function testFindOneWithEmptyDuplicateRelation()
 {
     EssayTableMap::doDeleteAll();
     $author = new Author();
     $author->setFirstName('Piet');
     $author->setLastName('Sous');
     $author->save();
     AuthorTableMap::clearInstancePool();
     EssayTableMap::clearInstancePool();
     $query = AuthorQuery::create()->useEssayRelatedByFirstAuthorIdQuery()->orderByTitle()->endUse()->with('EssayRelatedByFirstAuthorId');
     $author = $query->find()->get(0);
     // should not throw a notice
     $this->assertTrue(true);
 }
Пример #5
0
 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_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');
 }