コード例 #1
0
 /**
  * {@inheritdoc}
  *
  * @return RecordInterface
  * @see ORM::record()
  * @see Record::setContext()
  * @throws ORMException
  */
 public function current()
 {
     if (isset($this->instances[$this->position])) {
         //Due record was pre-constructed we must update it's context to force values for relations
         //and pivot fields
         return $this->instances[$this->position];
     }
     //Let's ask ORM to create needed record
     return $this->instances[$this->position] = $this->orm->record($this->class, $this->data[$this->position], $this->cache);
 }
コード例 #2
0
ファイル: Selector.php プロジェクト: jwdeitch/components
 /**
  * Fetch one record from database. Attention, LIMIT statement will be used, meaning you can not
  * use loaders for HAS_MANY or MANY_TO_MANY relations with data inload (joins), use default
  * loading method.
  *
  * @see findByPK()
  * @param array $where    Selection WHERE statement.
  * @param bool  $setLimit Use limit 1.
  * @return RecordEntity|null
  */
 public function findOne(array $where = [], $setLimit = true)
 {
     if (!empty($where)) {
         $this->where($where);
     }
     $data = $this->limit($setLimit ? 1 : null)->fetchData();
     if (empty($data)) {
         return null;
     }
     return $this->orm->record($this->class, $data[0]);
 }
コード例 #3
0
 /**
  * Fetch one record from database. Attention, LIMIT statement will be used, meaning you can not
  * use loaders for HAS_MANY or MANY_TO_MANY relations with data inload (joins), use default
  * loading method.
  *
  * @see findByPK()
  * @param array $where     Selection WHERE statement.
  * @param bool  $withLimit Use limit 1.
  * @return RecordEntity|null
  */
 public function findOne(array $where = [], $withLimit = true)
 {
     if (!empty($where)) {
         $this->where($where);
     }
     $data = $this->limit($withLimit ? 1 : null)->fetchData();
     if (empty($data)) {
         return null;
     }
     //Letting ORM to do it's job
     return $this->orm->record($this->class, $data[0]);
 }
コード例 #4
0
ファイル: Relation.php プロジェクト: spiral/components
 /**
  * Create empty record to be associated with non nullable relation.
  *
  * @return RecordEntity
  */
 protected function emptyRecord()
 {
     $record = $this->orm->record($this->getClass(), []);
     $this->associate($record);
     return $record;
 }