コード例 #1
0
 /**
  * Test behavior of columns that are implicated in multiple foreign keys.
  * @link       http://propel.phpdb.org/trac/ticket/228
  */
 public function testMultiFkImplication()
 {
     BookstoreDataPopulator::populate();
     // Create a new bookstore, contest, bookstore_contest, and bookstore_contest_entry
     $b = new Bookstore();
     $b->setStoreName("Foo!");
     $b->save();
     $c = new Contest();
     $c->setName("Bookathon Contest");
     $c->save();
     $bc = new BookstoreContest();
     $bc->setBookstore($b);
     $bc->setContest($c);
     $bc->save();
     $c = new Customer();
     $c->setName("Happy Customer");
     $c->save();
     $bce = new BookstoreContestEntry();
     $bce->setBookstore($b);
     $bce->setBookstoreContest($bc);
     $bce->setCustomer($c);
     $bce->save();
     $bce->setBookstoreId(null);
     $this->assertNull($bce->getBookstoreContest());
     $this->assertNull($bce->getBookstore());
 }
コード例 #2
0
 /**
  * Checks whether we are allowed to specify the primary key on a
  * table with allowPkInsert=true set
  *
  * saves the object, gets it from data-source again and then compares
  * them for equality (thus the instance pool is also checked)
  */
 public function testAllowPkInsertOnIdMethodNativeTable()
 {
     CustomerTableMap::doDeleteAll();
     $cu = new Customer();
     $cu->setPrimaryKey(100000);
     $cu->save();
     $this->assertEquals(100000, $cu->getPrimaryKey());
     $cu2 = CustomerQuery::create()->findPk(100000);
     $this->assertSame($cu, $cu2);
 }
コード例 #3
0
 /**
  * Test that cascading deletes are happening correctly for composite pk.
  * @link       http://propel.phpdb.org/trac/ticket/544
  */
 public function testDoDelete_Cascade_CompositePK()
 {
     $origBceCount = BookstoreContestEntryQuery::create()->count();
     $cust1 = new Customer();
     $cust1->setName("Cust1");
     $cust1->save();
     $cust2 = new Customer();
     $cust2->setName("Cust2");
     $cust2->save();
     $c1 = new Contest();
     $c1->setName("Contest1");
     $c1->save();
     $c2 = new Contest();
     $c2->setName("Contest2");
     $c2->save();
     $store1 = new Bookstore();
     $store1->setStoreName("Store1");
     $store1->save();
     $bc1 = new BookstoreContest();
     $bc1->setBookstore($store1);
     $bc1->setContest($c1);
     $bc1->save();
     $bc2 = new BookstoreContest();
     $bc2->setBookstore($store1);
     $bc2->setContest($c2);
     $bc2->save();
     $bce1 = new BookstoreContestEntry();
     $bce1->setEntryDate("now");
     $bce1->setCustomer($cust1);
     $bce1->setBookstoreContest($bc1);
     $bce1->save();
     $bce2 = new BookstoreContestEntry();
     $bce2->setEntryDate("now");
     $bce2->setCustomer($cust1);
     $bce2->setBookstoreContest($bc2);
     $bce2->save();
     // Now, if we remove $bc1, we expect *only* bce1 to be no longer valid.
     BookstoreContestTableMap::doDelete($bc1);
     $newCount = BookstoreContestEntryQuery::create()->count();
     $this->assertEquals($origBceCount + 1, $newCount, "Expected new number of rows in BCE to be orig + 1");
     $bcetest = BookstoreContestEntryQuery::create()->findPk(array($store1->getId(), $c1->getId(), $cust1->getId()));
     $this->assertNull($bcetest, "Expected BCE for store1 to be cascade deleted.");
     $bcetest2 = BookstoreContestEntryQuery::create()->findPk(array($store1->getId(), $c2->getId(), $cust1->getId()));
     $this->assertNotNull($bcetest2, "Expected BCE for store2 to NOT be cascade deleted.");
 }
コード例 #4
0
 /**
  * Checks wether we are allowed to specify the primary key on a
  * table with allowPkInsert=true set
  *
  * saves the object, gets it from data-source again and then compares
  * them for equality (thus the instance pool is also checked)
  */
 public function testAllowPkInsertOnIdMethodNativeTable()
 {
     CustomerPeer::doDeleteAll();
     $cu = new Customer();
     $cu->setPrimaryKey(100000);
     $cu->save();
     $this->assertEquals(100000, $cu->getPrimaryKey());
     $cu2 = CustomerPeer::retrieveByPk(100000);
     $this->assertSame($cu, $cu2);
 }
コード例 #5
0
 /**
  * Testing foreign keys with multiple referrer columns.
  * @link       http://propel.phpdb.org/trac/ticket/606
  */
 public function testMultiColJoin()
 {
     BookstoreContestPeer::doDeleteAll();
     BookstoreContestEntryPeer::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(array(BookstoreContestEntryPeer::BOOKSTORE_ID, BookstoreContestEntryPeer::CONTEST_ID), array(BookstoreContestPeer::BOOKSTORE_ID, BookstoreContestPeer::CONTEST_ID));
     $results = BookstoreContestEntryPeer::doSelect($c);
     $this->assertEquals(2, count($results));
     foreach ($results as $result) {
         $this->assertEquals($bs1Id, $result->getBookstoreId());
         $this->assertEquals($ct1Id, $result->getContestId());
     }
 }