/**
  * Check if relation configs are equal
  * @param \arogachev\ManyToMany\components\ManyToManyRelation $relation
  */
 protected function assertRelationConfigsEqual($relation)
 {
     $this->assertEquals($relation->table, 'tests_users');
     $this->assertEquals($relation->ownAttribute, 'test_id');
     $this->assertEquals($relation->relatedModel, User::className());
     $this->assertEquals($relation->relatedAttribute, 'user_id');
 }
Ejemplo n.º 2
0
 public static function getFields()
 {
     return ['name' => ['class' => CharField::className()], 'users' => ['class' => ManyToManyField::className(), 'modelClass' => User::className(), 'through' => Membership::className()]];
 }
Ejemplo n.º 3
0
 public static function getFields()
 {
     return ['user' => ['class' => ForeignField::className(), 'modelClass' => User::className(), 'relatedName' => 'addresses', 'null' => true], 'address' => ['class' => TextField::className()]];
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUsers()
 {
     return $this->hasMany(User::className(), ['id' => 'user_id'])->via('projectUsers');
 }
Ejemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUsersViaRelation()
 {
     return $this->hasMany(User::className(), ['id' => 'user_id'])->via('testUsers');
 }
 public function lookupProvider()
 {
     return [[Customer::className(), ['user__username' => 'Anton'], "SELECT COUNT(*) FROM `tests_customer` `tests_customer_1` LEFT OUTER JOIN `tests_user` `tests_user_2` ON `tests_customer_1`.`user_id` = `tests_user_2`.`id` WHERE (`tests_user_2`.`username`='Anton')", 2], [Customer::className(), ['user__username__startswith' => 'A'], "SELECT COUNT(*) FROM `tests_customer` `tests_customer_1` LEFT OUTER JOIN `tests_user` `tests_user_2` ON `tests_customer_1`.`user_id` = `tests_user_2`.`id` WHERE (`tests_user_2`.`username` LIKE 'A%')", 2], [Customer::className(), ['user__groups__name' => 'Administrators'], "SELECT COUNT(DISTINCT `tests_customer_1`.`id`) FROM `tests_customer` `tests_customer_1` LEFT OUTER JOIN `tests_user` `tests_user_2` ON `tests_customer_1`.`user_id` = `tests_user_2`.`id` LEFT OUTER JOIN `tests_membership` `tests_membership_3` ON `tests_user_2`.`id` = `tests_membership_3`.`user_id` LEFT OUTER JOIN `tests_group` `tests_group_4` ON `tests_membership_3`.`group_id` = `tests_group_4`.`id` WHERE (`tests_group_4`.`name`='Administrators')", 3], [Customer::className(), ['user__groups__name__endswith' => 's'], "SELECT COUNT(DISTINCT `tests_customer_1`.`id`) FROM `tests_customer` `tests_customer_1` LEFT OUTER JOIN `tests_user` `tests_user_2` ON `tests_customer_1`.`user_id` = `tests_user_2`.`id` LEFT OUTER JOIN `tests_membership` `tests_membership_3` ON `tests_user_2`.`id` = `tests_membership_3`.`user_id` LEFT OUTER JOIN `tests_group` `tests_group_4` ON `tests_membership_3`.`group_id` = `tests_group_4`.`id` WHERE (`tests_group_4`.`name` LIKE '%s')", 3], [User::className(), ['addresses__address__contains' => 'Anton'], "SELECT COUNT(DISTINCT `tests_user_1`.`id`) FROM `tests_user` `tests_user_1` LEFT OUTER JOIN `tests_customer` `tests_customer_2` ON `tests_user_1`.`id` = `tests_customer_2`.`user_id` WHERE (`tests_customer_2`.`address` LIKE '%Anton%')", 1], [Customer::className(), ['user__username' => 'Max', 'user__pk' => '2'], "SELECT COUNT(*) FROM `tests_customer` `tests_customer_1` LEFT OUTER JOIN `tests_user` `tests_user_2` ON `tests_customer_1`.`user_id` = `tests_user_2`.`id` WHERE (`tests_user_2`.`username`='Max') AND (`tests_user_2`.`id`='2')", 1], [Customer::className(), ['user__username' => 'Max', 'user__groups__pk' => '1'], "SELECT COUNT(DISTINCT `tests_customer_1`.`id`) FROM `tests_customer` `tests_customer_1` LEFT OUTER JOIN `tests_user` `tests_user_2` ON `tests_customer_1`.`user_id` = `tests_user_2`.`id` LEFT OUTER JOIN `tests_membership` `tests_membership_3` ON `tests_user_2`.`id` = `tests_membership_3`.`user_id` LEFT OUTER JOIN `tests_group` `tests_group_4` ON `tests_membership_3`.`group_id` = `tests_group_4`.`id` WHERE (`tests_user_2`.`username`='Max') AND (`tests_group_4`.`id`='1')", 1]];
 }
Ejemplo n.º 7
0
 public static function getFields()
 {
     return ['group' => ['class' => ForeignField::className(), 'modelClass' => Group::className()], 'user' => ['class' => ForeignField::className(), 'modelClass' => User::className()]];
 }
 public function lookupProvider()
 {
     return [[Customer::className(), ['user__username' => 'Anton'], 'SELECT COUNT(*) FROM "tests_customer" "tests_customer_1" LEFT OUTER JOIN "tests_user" "tests_user_2" ON "tests_customer_1"."user_id" = "tests_user_2"."id" WHERE ("tests_user_2"."username"=\'Anton\')', 2], [Customer::className(), ['user__username__startswith' => 'A'], 'SELECT COUNT(*) FROM "tests_customer" "tests_customer_1" LEFT OUTER JOIN "tests_user" "tests_user_2" ON "tests_customer_1"."user_id" = "tests_user_2"."id" WHERE ("tests_user_2"."username" LIKE \'A%\')', 2], [Customer::className(), ['user__groups__name' => 'Administrators'], 'SELECT COUNT(DISTINCT "tests_customer_1"."id") FROM "tests_customer" "tests_customer_1" LEFT OUTER JOIN "tests_user" "tests_user_2" ON "tests_customer_1"."user_id" = "tests_user_2"."id" LEFT OUTER JOIN "tests_membership" "tests_membership_3" ON "tests_user_2"."id" = "tests_membership_3"."user_id" LEFT OUTER JOIN "tests_group" "tests_group_4" ON "tests_membership_3"."group_id" = "tests_group_4"."id" WHERE ("tests_group_4"."name"=\'Administrators\')', 3], [Customer::className(), ['user__groups__name__endswith' => 's'], 'SELECT COUNT(DISTINCT "tests_customer_1"."id") FROM "tests_customer" "tests_customer_1" LEFT OUTER JOIN "tests_user" "tests_user_2" ON "tests_customer_1"."user_id" = "tests_user_2"."id" LEFT OUTER JOIN "tests_membership" "tests_membership_3" ON "tests_user_2"."id" = "tests_membership_3"."user_id" LEFT OUTER JOIN "tests_group" "tests_group_4" ON "tests_membership_3"."group_id" = "tests_group_4"."id" WHERE ("tests_group_4"."name" LIKE \'%s\')', 3], [User::className(), ['addresses__address__contains' => 'Anton'], 'SELECT COUNT(DISTINCT "tests_user_1"."id") FROM "tests_user" "tests_user_1" LEFT OUTER JOIN "tests_customer" "tests_customer_2" ON "tests_user_1"."id" = "tests_customer_2"."user_id" WHERE ("tests_customer_2"."address" LIKE \'%Anton%\')', 1], [Customer::className(), ['user__username' => 'Max', 'user__pk' => '2'], 'SELECT COUNT(*) FROM "tests_customer" "tests_customer_1" LEFT OUTER JOIN "tests_user" "tests_user_2" ON "tests_customer_1"."user_id" = "tests_user_2"."id" WHERE ("tests_user_2"."username"=\'Max\') AND ("tests_user_2"."id"=\'2\')', 1], [Customer::className(), ['user__username' => 'Max', 'user__groups__pk' => '1'], 'SELECT COUNT(DISTINCT "tests_customer_1"."id") FROM "tests_customer" "tests_customer_1" LEFT OUTER JOIN "tests_user" "tests_user_2" ON "tests_customer_1"."user_id" = "tests_user_2"."id" LEFT OUTER JOIN "tests_membership" "tests_membership_3" ON "tests_user_2"."id" = "tests_membership_3"."user_id" LEFT OUTER JOIN "tests_group" "tests_group_4" ON "tests_membership_3"."group_id" = "tests_group_4"."id" WHERE ("tests_user_2"."username"=\'Max\') AND ("tests_group_4"."id"=\'1\')', 1]];
 }