コード例 #1
0
 public function testI18nWithRelations2()
 {
     \MovieQuery::create()->deleteAll();
     $count = \MovieQuery::create()->count();
     $this->assertEquals(0, $count, 'No movie before the test');
     \ToyQuery::create()->deleteAll();
     $count = \ToyQuery::create()->count();
     $this->assertEquals(0, $count, 'No toy before the test');
     \ToyI18nQuery::create()->deleteAll();
     $count = \ToyI18nQuery::create()->count();
     $this->assertEquals(0, $count, 'No i18n toys before the test');
     \MovieI18nQuery::create()->deleteAll();
     $count = \MovieI18nQuery::create()->count();
     $this->assertEquals(0, $count, 'No i18n movies before the test');
     $t = new \Toy();
     $t->setLocale('en');
     $t->setName('My Name');
     $t->setLocale('fr');
     $t->setName('Mon Nom');
     $t->setLocale('en');
     $this->assertEquals('My Name', $t->getName());
     $t->setLocale('fr');
     $this->assertEquals('Mon Nom', $t->getName());
     $m = new \Movie();
     $m->addToy($t);
     $m->save();
     $count = \MovieQuery::create()->count();
     $this->assertEquals(1, $count, '1 movie');
     $count = \ToyQuery::create()->count();
     $this->assertEquals(1, $count, '1 toy');
     $count = \ToyI18nQuery::create()->count();
     $this->assertEquals(2, $count, '2 i18n toys');
     $count = \MovieI18nQuery::create()->count();
     $this->assertEquals(0, $count, '0 i18n movies');
 }
コード例 #2
0
ファイル: index.php プロジェクト: rubensayshi/propelsandbox
<?php

// Include the main Propel script
require_once dirname(__FILE__) . '/vendor/propel/runtime/lib/Propel.php';
// Initialize Propel with the runtime configuration
Propel::init(dirname(__FILE__) . "/build/conf/propelsandbox-conf.php");
// Add the generated 'classes' directory to the include path
set_include_path(dirname(__FILE__) . "/build/classes" . PATH_SEPARATOR . get_include_path());
$con = Propel::getConnection();
$con->setLogLevel(Propel::LOG_DEBUG);
$con->useDebug(true);
$movie = MovieQuery::create()->findPK(1);
$q = PersonQuery::create()->filterByMovie($movie);
var_dump($q->find());
/*
$person = new Person();
$person->setName("Ruben");
$person->save();

$movie = new Movie();
$movie->setTitle("RAWR");
$movie->addPerson($person);
$movie->save();
//*/
コード例 #3
0
 /**
  * Gets the number of Movie objects related by a many-to-many relationship
  * to the current object by way of the moviesPersons cross-reference table.
  *
  * @param      Criteria $criteria Optional query object to filter the query
  * @param      boolean $distinct Set to true to force count distinct
  * @param      PropelPDO $con Optional connection object
  *
  * @return     int the number of related Movie objects
  */
 public function countMovies($criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if (null === $this->collMovies || null !== $criteria) {
         if ($this->isNew() && null === $this->collMovies) {
             return 0;
         } else {
             $query = MovieQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByPerson($this)->count($con);
         }
     } else {
         return count($this->collMovies);
     }
 }
コード例 #4
0
 /**
  * Get the associated Movie object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Movie The associated Movie object.
  * @throws     PropelException
  */
 public function getMovie(PropelPDO $con = null)
 {
     if ($this->aMovie === null && $this->movieid !== null) {
         $this->aMovie = MovieQuery::create()->findPk($this->movieid, $con);
         /* The following can be used additionally to
         			guarantee the related object contains a reference
         			to this object.  This level of coupling may, however, be
         			undesirable since it could result in an only partially populated collection
         			in the referenced object.
         			$this->aMovie->addMoviespersonss($this);
         		 */
     }
     return $this->aMovie;
 }
コード例 #5
0
 /**
  * Returns a new MovieQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return    MovieQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof MovieQuery) {
         return $criteria;
     }
     $query = new MovieQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
コード例 #6
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return     void
  * @throws     PropelException
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(MoviePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $ret = $this->preDelete($con);
         if ($ret) {
             MovieQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }