本文整理汇总了PHP中Propel\Runtime\ActiveQuery\Criteria::addJoin方法的典型用法代码示例。如果您正苦于以下问题:PHP Criteria::addJoin方法的具体用法?PHP Criteria::addJoin怎么用?PHP Criteria::addJoin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Runtime\ActiveQuery\Criteria
的用法示例。
在下文中一共展示了Criteria::addJoin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDoDeleteJoin
/**
* @expectedException \Propel\Runtime\Exception\PropelException
*/
public function testDoDeleteJoin()
{
$con = Propel::getServiceContainer()->getWriteConnection(BookTableMap::DATABASE_NAME);
$c = new Criteria(BookTableMap::DATABASE_NAME);
$c->add(BookTableMap::COL_TITLE, 'War And Peace');
$c->addJoin(BookTableMap::COL_AUTHOR_ID, AuthorTableMap::COL_ID);
$c->doDelete($con);
}
示例2: testMergeWithJoins
public function testMergeWithJoins()
{
$c1 = new Criteria();
$c1->addJoin(BookTableMap::COL_AUTHOR_ID, AuthorTableMap::COL_ID, Criteria::LEFT_JOIN);
$c2 = new Criteria();
$c1->mergeWith($c2);
$joins = $c1->getJoins();
$this->assertEquals(1, count($joins), 'mergeWith() does not remove an existing join');
$this->assertEquals('LEFT JOIN author ON (book.AUTHOR_ID=author.ID)', $joins[0]->toString(), 'mergeWith() does not remove an existing join');
$c1 = new Criteria();
$c2 = new Criteria();
$c2->addJoin(BookTableMap::COL_AUTHOR_ID, AuthorTableMap::COL_ID, Criteria::LEFT_JOIN);
$c1->mergeWith($c2);
$joins = $c1->getJoins();
$this->assertEquals(1, count($joins), 'mergeWith() merge joins to an empty join');
$this->assertEquals('LEFT JOIN author ON (book.AUTHOR_ID=author.ID)', $joins[0]->toString(), 'mergeWith() merge joins to an empty join');
$c1 = new Criteria();
$c1->addJoin(BookTableMap::COL_AUTHOR_ID, AuthorTableMap::COL_ID, Criteria::LEFT_JOIN);
$c2 = new Criteria();
$c2->addJoin(BookTableMap::COL_PUBLISHER_ID, PublisherTableMap::COL_ID, Criteria::INNER_JOIN);
$c1->mergeWith($c2);
$joins = $c1->getJoins();
$this->assertEquals(2, count($joins), 'mergeWith() merge joins to an existing join');
$this->assertEquals('LEFT JOIN author ON (book.AUTHOR_ID=author.ID)', $joins[0]->toString(), 'mergeWith() merge joins to an empty join');
$this->assertEquals('INNER JOIN publisher ON (book.PUBLISHER_ID=publisher.ID)', $joins[1]->toString(), 'mergeWith() merge joins to an empty join');
}
示例3: testAddJoin_Duplicate
/**
* Tests adding duplicate joins.
* @link http://propel.phpdb.org/trac/ticket/613
*/
public function testAddJoin_Duplicate()
{
$c = new Criteria();
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::LEFT_JOIN);
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::LEFT_JOIN);
$this->assertEquals(1, count($c->getJoins()), "Expected not to have duplicate LJOIN added.");
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::RIGHT_JOIN);
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::RIGHT_JOIN);
$this->assertEquals(2, count($c->getJoins()), "Expected 1 new right join to be added.");
$c->addJoin("tbl.COL1", "tbl.COL2");
$c->addJoin("tbl.COL1", "tbl.COL2");
$this->assertEquals(3, count($c->getJoins()), "Expected 1 new implicit join to be added.");
$c->addJoin("tbl.COL3", "tbl.COL4");
$this->assertEquals(4, count($c->getJoins()), "Expected new col join to be added.");
}
示例4: testMultiColJoin
/**
* Testing foreign keys with multiple referrer columns.
* @link http://propel.phpdb.org/trac/ticket/606
*/
public function testMultiColJoin()
{
BookstoreContestTableMap::doDeleteAll();
BookstoreContestEntryTableMap::doDeleteAll();
$bs = new Bookstore();
$bs->setStoreName("Test1");
$bs->setPopulationServed(5);
$bs->save();
$bs1Id = $bs->getId();
$bs2 = new Bookstore();
$bs2->setStoreName("Test2");
$bs2->setPopulationServed(5);
$bs2->save();
$bs2Id = $bs2->getId();
$ct1 = new Contest();
$ct1->setName("Contest1!");
$ct1->save();
$ct1Id = $ct1->getId();
$ct2 = new Contest();
$ct2->setName("Contest2!");
$ct2->save();
$ct2Id = $ct2->getId();
$cmr = new Customer();
$cmr->setName("Customer1");
$cmr->save();
$cmr1Id = $cmr->getId();
$cmr2 = new Customer();
$cmr2->setName("Customer2");
$cmr2->save();
$cmr2Id = $cmr2->getId();
$contest = new BookstoreContest();
$contest->setBookstoreId($bs1Id);
$contest->setContestId($ct1Id);
$contest->save();
$contest = new BookstoreContest();
$contest->setBookstoreId($bs2Id);
$contest->setContestId($ct1Id);
$contest->save();
$entry = new BookstoreContestEntry();
$entry->setBookstoreId($bs1Id);
$entry->setContestId($ct1Id);
$entry->setCustomerId($cmr1Id);
$entry->save();
$entry = new BookstoreContestEntry();
$entry->setBookstoreId($bs1Id);
$entry->setContestId($ct1Id);
$entry->setCustomerId($cmr2Id);
$entry->save();
// Note: this test isn't really working very well. We setup fkeys that
// require that the BookstoreContest rows exist and then try to violate
// the rules ... :-/ This may work in some lenient databases, but an error
// is expected here.
/*
* Commented out for now ... though without it, this test may not really be testing anything
$entry = new BookstoreContestEntry();
$entry->setBookstoreId($bs1Id);
$entry->setContestId($ct2Id);
$entry->setCustomerId($cmr2Id);
$entry->save();
*/
$c = new Criteria();
$c->addJoin([BookstoreContestEntryTableMap::BOOKSTORE_ID, BookstoreContestEntryTableMap::CONTEST_ID], [BookstoreContestTableMap::BOOKSTORE_ID, BookstoreContestTableMap::CONTEST_ID]);
$results = BookstoreContestEntryQuery::create(null, $c)->find();
$this->assertEquals(2, count($results));
foreach ($results as $result) {
$this->assertEquals($bs1Id, $result->getBookstoreId());
$this->assertEquals($ct1Id, $result->getContestId());
}
}