atk4\data\Model::tryLoadAny PHP Method

tryLoadAny() public method

Will not throw exception if record doesn't exist.
public tryLoadAny ( )
    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;
    }

Usage Example

Example #1
0
 public function testNakedExpression()
 {
     $db = new Persistence_SQL($this->db->connection);
     $m = new Model($db, false);
     $m->addExpression('x', '2+3');
     $m->tryLoadAny();
     $this->assertEquals(5, $m['x']);
 }
All Usage Examples Of atk4\data\Model::tryLoadAny