示例#1
0
文件: Query.php 项目: matak/dbrecord
 private function resolveTable($arg)
 {
     if ($arg == '#') {
         $path = array('base');
     } else {
         $path = explode('.', trim($arg, '.#'));
         array_unshift($path, "base");
     }
     foreach ($path as $index => $item) {
         if ($item == 'base') {
             $metadata = $this->repository->getMetadata();
             $table = $metadata->getTable();
             $tableAs = 'base';
             if (!$this->getTableAs($tableAs)) {
                 $this->setTableAs($tableAs, $table, $metadata);
             }
         } else {
             //	tabulka
             $association = $metadata->getAssociation($item);
             $associationClassName = $association->getReferenceClass();
             $associationMetadata = $this->repository->getEntityManager()->getRepository($associationClassName)->getMetadata();
             $parentTable = $table;
             $parentTableAs = $tableAs;
             $table = $associationMetadata->getTable();
             $tableAs = $tableAs . self::ALIAS_SEPARATOR . $item;
             //	Nevytvaret novy stejny join. Jen, pokud je jina vazba, nebo jiny nazev.
             if (!$this->getTableAs($tableAs)) {
                 $this->setTableAs($tableAs, $table, $metadata, $parentTableAs, $association);
             }
         }
     }
     return $tableAs;
 }
示例#2
0
 /**
  * 
  * @param type $pk
  * @return item|null
  */
 public function pk($pk)
 {
     $pkName = $this->repository->getMetadata()->getPrimaryColumn();
     foreach ($this as $item) {
         if ($item->{$pkName} == $pk) {
             return $item;
         }
     }
     return NULL;
 }