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 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); }
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() { 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_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(BookPeer::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'); }