Example #1
0
 public static function getFields()
 {
     return ['name' => ['class' => CharField::className()], 'users' => ['class' => ManyToManyField::className(), 'modelClass' => User::className(), 'through' => Membership::className()]];
 }
 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));
 }
Example #3
0
 public static function getFields()
 {
     return ['username' => ['class' => CharField::className(), 'validators' => [new MinLengthValidator(3), new MaxLengthValidator(20)]], 'password' => ['class' => PasswordField::className(), 'null' => true], 'groups' => ['class' => ManyToManyField::className(), 'modelClass' => Group::className(), 'through' => Membership::className()], 'addresses' => ['class' => HasManyField::className(), 'modelClass' => Customer::className(), 'relatedName' => 'user', 'editable' => false]];
 }