/** * Returns a new PersonQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return PersonQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof PersonQuery) { return $criteria; } $query = new PersonQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
<?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(); //*/
/** * 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(PersonPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $ret = $this->preDelete($con); if ($ret) { PersonQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (PropelException $e) { $con->rollBack(); throw $e; } }
/** * Get the associated Person object * * @param PropelPDO Optional Connection object. * @return Person The associated Person object. * @throws PropelException */ public function getPerson(PropelPDO $con = null) { if ($this->aPerson === null && $this->personid !== null) { $this->aPerson = PersonQuery::create()->findPk($this->personid, $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->aPerson->addMoviespersonss($this); */ } return $this->aPerson; }
public function testFindFriendsOf() { $john = new Person(); $john->setName('john'); $john->save(); $jean = new Person(); $jean->setName('jean'); $jean->save(); $phil = new Person(); $phil->setName('phil'); $phil->save(); $this->assertEquals(0, PersonQuery::create()->findFriendsOf($phil)->count()); $this->assertEquals(0, PersonQuery::create()->findFriendsOf($jean)->count()); $this->assertEquals(0, PersonQuery::create()->findFriendsOf($john)->count()); $jean->addFriend($phil); $this->assertEquals(0, PersonQuery::create()->findFriendsOf($phil)->count()); $this->assertEquals(0, PersonQuery::create()->findFriendsOf($jean)->count()); $jean->save(); $this->assertEquals(1, PersonQuery::create()->findFriendsOf($phil)->count()); $this->assertEquals(1, PersonQuery::create()->findFriendsOf($jean)->count()); $coll = PersonQuery::create()->findFriendsOf($phil); $this->assertInstanceOf('PropelObjectCollection', $coll); $this->assertInstanceOf('Person', $coll[0]); $this->assertEquals('jean', $coll[0]->getName()); $coll = PersonQuery::create()->findFriendsOf($jean); $this->assertInstanceOf('PropelObjectCollection', $coll); $this->assertInstanceOf('Person', $coll[0]); $this->assertEquals('phil', $coll[0]->getName()); $jean->removeFriends(); $jean->save(); $this->assertEquals(0, FriendQuery::create()->count()); $this->assertEquals(0, PersonQuery::create()->findFriendsOf($phil)->count()); $this->assertEquals(0, PersonQuery::create()->findFriendsOf($jean)->count()); }
public function editPerson($id, $company, $firstname, $lastname, $address, $zip, $city) { PersonQuery::create()->findOneById($id)->setCompany($company)->setFirstname($firstname)->setLastname($lastname)->setAddress($address)->setCity($city)->setZip($zip)->save(); }
/** * Gets the number of Person 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 Person objects */ public function countPersons($criteria = null, $distinct = false, PropelPDO $con = null) { if (null === $this->collPersons || null !== $criteria) { if ($this->isNew() && null === $this->collPersons) { return 0; } else { $query = PersonQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByMovie($this)->count($con); } } else { return count($this->collPersons); } }