Example #1
0
 public function testEagerLoadBelongsToSimpleMany()
 {
     // Find kid with id `3`
     $kid3 = Model\Kid::with('user')->find(3);
     // Consist
     $this->assertInstanceOf('Gas\\ORM', $kid3);
     $this->assertInstanceOf('Gas\\Data', $kid3->record);
     // Check result
     $this->assertEquals($kid3->id, '3');
     $this->assertEquals($kid3->name, 'Abraham Jones');
     $this->assertEquals($kid3->age, '3');
     // Grab related father (user)
     $kid3_father = $kid3->user();
     // Consist
     $this->assertInstanceOf('Gas\\ORM', $kid3_father);
     $this->assertInstanceOf('Gas\\Data', $kid3_father->record);
     // Check results, this should be `Derek Jones` with `2` as his id
     // and `derek` as his username
     $this->assertEquals($kid3_father->id, '2');
     $this->assertEquals($kid3_father->name, 'Derek Jones');
     $this->assertEquals($kid3_father->username, 'derek');
     // Since the third parameter for kid <-> user relationship
     // contain `select:id,name,username` for pre-process relation
     // Other fields should be null
     $this->assertNull($kid3_father->email);
 }