Esempio n. 1
0
 /**
  * loadRelated
  *
  * @param mixed $name
  * @return boolean
  */
 public function loadRelated($name = null)
 {
     $list = array();
     $query = new Doctrine_Query($this->_table->getConnection());
     if (!isset($name)) {
         foreach ($this->data as $record) {
             $value = $record->getIncremented();
             if ($value !== null) {
                 $list[] = $value;
             }
         }
         $query->from($this->_table->getComponentName() . '(' . implode(", ", $this->_table->getPrimaryKeys()) . ')');
         $query->where($this->_table->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)), 0, -2) . ')');
         return $query;
     }
     $rel = $this->_table->getRelation($name);
     if ($rel instanceof Doctrine_Relation_LocalKey || $rel instanceof Doctrine_Relation_ForeignKey) {
         foreach ($this->data as $record) {
             $list[] = $record[$rel->getLocal()];
         }
     } else {
         foreach ($this->data as $record) {
             $value = $record->getIncremented();
             if ($value !== null) {
                 $list[] = $value;
             }
         }
     }
     $dql = $rel->getRelationDql(count($list), 'collection');
     $coll = $query->query($dql, $list);
     $this->populateRelated($name, $coll);
 }