hasMany() 공개 메소드

Add hasMany field.
public hasMany ( string $link, array $defaults = [] ) : Reference_Many
$link string
$defaults array
리턴 Reference_Many
예제 #1
0
파일: ReferenceTest.php 프로젝트: atk4/data
 public function testBasicReferences()
 {
     $user = new Model(['table' => 'user']);
     $user->addField('name');
     $user->id = 1;
     $order = new Model();
     $order->addField('amount', ['default' => 20]);
     $order->addField('user_id');
     $user->hasMany('Orders', $order);
     $o = $user->ref('Orders');
     $this->assertEquals(20, $o['amount']);
     $this->assertEquals(1, $o['user_id']);
     $user->hasMany('BigOrders', function () {
         $m = new Model();
         $m->addField('amount', ['default' => 100]);
         $m->addField('user_id');
         return $m;
     });
     $this->assertEquals(100, $user->ref('BigOrders')['amount']);
 }
예제 #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);
 }