public function testSubqueryIn()
 {
     $qs = Group::objects()->filter(['id' => 1]);
     $users = User::objects()->filter(['groups__pk__in' => $qs->select('id')])->all();
     $this->assertEquals(count($users), 1);
     $this->assertEquals($users[0]->username, 'Max');
 }
 public function testVia()
 {
     $group = new Group();
     $group->name = 'Administrators';
     $this->assertNull($group->pk);
     $this->assertInstanceOf('\\Mindy\\Orm\\ManyToManyManager', $group->users);
     $this->assertEquals(0, $group->users->count());
     $this->assertEquals([], $group->users->all());
     $this->assertTrue($group->save());
     $this->assertEquals(1, $group->pk);
     $user = new User();
     $user->username = '******';
     $user->password = '******';
     $this->assertTrue($user->save());
     $this->assertEquals(0, count($group->users->all()));
     $group->users->link($user);
     $this->assertEquals(1, count($group->users->all()));
     $new = Group::objects()->get(['id' => 1]);
     $this->assertEquals(1, count($new->users->all()));
     $memberships = Membership::objects()->filter(['group_id' => 1, 'user_id' => 1])->all();
     $this->assertEquals(1, count($memberships));
 }
 public function testExactQs()
 {
     $group = Group::objects()->filter(['pk' => 1])->get();
     $this->assertEquals(1, Group::objects()->count());
     $this->assertEquals(2, $group->users->count());
     $user = User::objects()->filter(['pk' => 1])->get();
     $customer = Customer::objects()->filter(['user' => $user])->get();
     $this->assertEquals(1, $customer->pk);
 }