예제 #1
0
파일: Model.php 프로젝트: atk4/data
 /**
  * Try to load any record.
  * Will not throw exception if record doesn't exist.
  *
  * @return $this
  */
 public function tryLoadAny()
 {
     if (!$this->persistence) {
         throw new Exception(['Model is not associated with any database']);
     }
     if ($this->loaded()) {
         $this->unload();
     }
     $this->data = $this->persistence->tryLoadAny($this);
     if ($this->data) {
         $this->id = $this->data[$this->id_field];
         $this->hook('afterLoad');
     } else {
         $this->unload();
     }
     return $this;
 }