Example #1
0
File: Model.php Project: atk4/data
 /**
  * Try to load record.
  * Will not throw exception if record doesn't exist.
  *
  * @param mixed $id
  *
  * @return $this
  */
 public function tryLoad($id)
 {
     if (!$this->persistence) {
         throw new Exception(['Model is not associated with any database']);
     }
     if ($this->loaded()) {
         $this->unload();
     }
     $this->data = $this->persistence->tryLoad($this, $id);
     if ($this->data) {
         $this->id = $id;
         $this->hook('afterLoad');
     } else {
         $this->unload();
     }
     return $this;
 }