public function testCreatingModelWithMultiInverseRelations()
 {
     $users = new User(['name' => 'safastak']);
     $role = Role::createWith(['alias' => 'admin'], compact('users'));
     $this->assertInstanceOf('Vinelab\\NeoEloquent\\Tests\\Functional\\QueryingRelations\\Role', $role);
     $this->assertTrue($role->exists);
     $this->assertGreaterThanOrEqual(0, $role->id);
     $related = $role->users->first();
     $this->assertNotNull($related->created_at);
     $this->assertNotNull($related->updated_at);
     $attrs = $related->toArray();
     unset($attrs['id']);
     unset($attrs['created_at']);
     unset($attrs['updated_at']);
     $usersArray = $users->toArray();
     unset($usersArray['id']);
     unset($usersArray['created_at']);
     unset($usersArray['updated_at']);
     $this->assertEquals($attrs, $usersArray);
 }
Exemplo n.º 2
0
 public function testQueryingRelatedModel()
 {
     $user = User::createWith(['name' => 'Beluga'], ['roles' => [['title' => 'Read Things', 'alias' => 'read'], ['title' => 'Write Things', 'alias' => 'write']]]);
     $read = Role::where('alias', 'read')->first();
     $this->assertEquals('read', $read->alias);
     $readFound = $user->roles()->where('alias', 'read')->first();
     $this->assertInstanceOf('Vinelab\\NeoEloquent\\Tests\\Functional\\QueryingRelations\\Role', $readFound);
     $this->assertEquals($read, $readFound);
     $write = Role::where('alias', 'write')->first();
     $this->assertEquals('write', $write->alias);
     $writeFound = $user->roles()->where('alias', 'write')->first();
     $this->assertEquals($write, $writeFound);
 }