Doctrine of many many

I have a question about Doctrine ORM M: M. I created several tables: -User + id + name -Group + id + Name

I want to link this table using a new table using Doctrine: In a group class:

$this->hasMany('User as Users', array(
            // I'm wondering what I can fill here
            'refClass' => 'UserGroup'
        ));

and in the User class:

 $this->hasMany('Group as Groups', array(
                // I'm wondering what I can fill here
                'refClass' => 'UserGroup'
            ));

Please help me fill in the blank. Thank you Waiting to hear from you soon.

P / S: Sorry for my English

+3
source share
2 answers

There is good documentation for this http://www.doctrine-project.org/documentation/manual/1_2/en/defining-models#relationships:join-table-associations:many-to-many serving your particular model.

This code is basically in the class of the User table:

$this->hasMany('Group as Groups', array(
                'local' => 'user_id',
                'foreign' => 'group_id',
                'refClass' => 'UserGroup'
            )
        );

, UserGroup. "user_id" UserGroup - , (User), "group_id" - , ().

Group :

$this->hasMany('User', array(
                'foreign' => 'user_id',
                'local' => 'group_id',
                'refClass' => 'UserGroup'
            )
        );
+1

$this->hasMany('User as Users', array(
  'refClass' => 'UserGroup',
  'local' => 'group_id',
  'foreign' => 'user_id');

:

$this->hasMany('Group as Groups', array(
  'refClass' => 'UserGroup',
  'local' => 'user_id',
  'foreign' => 'group_id');
0

Source: https://habr.com/ru/post/1741852/


All Articles