Ejemplo n.º 1
0
 /**
  * Returns a new ChildCategoryQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildCategoryQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildCategoryQuery) {
         return $criteria;
     }
     $query = new ChildCategoryQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Ejemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $title = $input->getArgument(AddBookCommand::TITLE);
     $description = $input->getArgument(AddBookCommand::DESCRIPTION);
     $categoryName = $input->getArgument(AddBookCommand::CATEGORY);
     $category = CategoryQuery::create()->filterByName($categoryName)->findOne();
     if ($category == null) {
         $output->writeln("No category named '" . $categoryName . "'. The category will be added.");
         $category = new Category();
         $category->setName($categoryName);
     }
     $book = new Book();
     $book->setTitle($title);
     $book->setDescription($description);
     $book->setCategory($category);
     $book->save();
     $output->writeln("Book '" . $title . "' successfully added.");
 }
Ejemplo n.º 3
0
 /**
  * Gets the number of Category objects related by a many-to-many relationship
  * to the current object by way of the object_category cross-reference table.
  *
  * @param      Criteria $criteria Optional query object to filter the query
  * @param      boolean $distinct Set to true to force count distinct
  * @param      ConnectionInterface $con Optional connection object
  *
  * @return int the number of related Category objects
  */
 public function countCategories(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collCategoriesPartial && !$this->isNew();
     if (null === $this->collCategories || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collCategories) {
             return 0;
         } else {
             if ($partial && !$criteria) {
                 return count($this->getCategories());
             }
             $query = ChildCategoryQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByObject($this)->count($con);
         }
     } else {
         return count($this->collCategories);
     }
 }
Ejemplo n.º 4
0
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @throws LogicException if no primary key is defined
  *
  * @return Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = ChildCategoryQuery::create();
     $criteria->add(CategoryTableMap::COL_ID, $this->id);
     return $criteria;
 }
Ejemplo n.º 5
0
 /**
  * Get the associated ChildCategory object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildCategory The associated ChildCategory object.
  * @throws PropelException
  */
 public function getCategory(ConnectionInterface $con = null)
 {
     if ($this->aCategory === null && $this->id_category !== null) {
         $this->aCategory = ChildCategoryQuery::create()->findPk($this->id_category, $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->aCategory->addObjectCategories($this);
            */
     }
     return $this->aCategory;
 }