ref() public method

Traverse to related model.
public ref ( string $link, array $defaults = [] ) : Model
$link string
$defaults array
return Model
Exemplo n.º 1
0
 public function testCustomRef()
 {
     $a = [];
     $p = new \atk4\data\Persistence_Array($a);
     $m = new Model($p, ['table' => 'user']);
     $m->addRef('archive', function ($m) {
         return $m->newInstance(null, ['table' => $m->table . '_archive']);
     });
     $this->assertEquals('user_archive', $m->ref('archive')->table);
 }
Exemplo n.º 2
0
 public function testModelProperty()
 {
     $db = new Persistence_SQL($this->db->connection);
     $user = new Model($db, ['table' => 'user']);
     $user->hasMany('Orders', ['model' => ['atk4/data/Model', 'table' => 'order'], 'their_field' => 'id']);
     $o = $user->ref('Orders');
     $this->assertEquals('order', $o->table);
 }