Ejemplo n.º 1
0
 /**
  * @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);
 }
Ejemplo n.º 2
0
 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');
 }
Ejemplo n.º 3
0
 /**
  * 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.");
 }
Ejemplo n.º 4
0
 /**
  * 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());
     }
 }