public function testQueryingParentWithMultipleWhereHas() { $user = User::create(['name' => 'cappuccino']); $role = Role::create(['alias' => 'pikachu']); $account = Account::create(['guid' => uniqid()]); $user->roles()->save($role); $user->account()->save($account); $found = User::whereHas('roles', function ($q) use($role) { $q->where('id', $role->id); })->whereHas('account', function ($q) use($account) { $q->where('id', $account->id); })->where('id', $user->id)->first(); $this->assertInstanceOf('Vinelab\\NeoEloquent\\Tests\\Functional\\QueryingRelations\\User', $found); $this->assertEquals($user->toArray(), $found->toArray()); }
public function testDoubleInverseEagerLoadingBelongsToRelationship() { $user = User::createWith(['name' => 'cappuccino'], ['organization' => ['name' => 'Pokemon']]); // Eager load so that when we assert we make sure they're there $role = Role::create(['alias' => 'pikachu']); $user->roles()->save($role); // Eager load so that when we assert we make sure they're there $org = $role->users->first()->organization; $roleFound = Role::with('users.organization')->whereHas('users', function ($q) use($user) { $q->where('id', $user->getKey()); })->first(); $this->assertInstanceOf('Vinelab\\NeoEloquent\\Tests\\Functional\\QueryingRelations\\Role', $roleFound); $this->assertArrayHasKey('users', $roleFound->getRelations()); $this->assertArrayHasKey('organization', $roleFound->users->first()->getRelations()); $this->assertEquals('Pokemon', $roleFound->users->first()->organization->name); $this->assertEquals($role->toArray(), $roleFound->toArray()); }