1. it seems that you want a ManyToMany relation between Group and User (a 
User can be a member of many groups and a Group can have many users). Then 
there is no necessity to make Member a separate entitiy; only do that if 
membership has some extra properties or behaviour. In the simplest case you 
can just have group_members as a join-table, but it doesn't need to be a 
separate entity. If you need it to be a separate entity I would not call it 
Member, but Membership or Subscription or something else that describes 
that entity.

2. If you want all members/users of a group, easiest is to make that 
relationship bidirectional: then you'll have a $members collection in a 
Group and do a $group->getMembers() to retrieve the users of that Group.


On Tuesday, 1 April 2014 10:10:51 UTC+2, Swapna V wrote:
>
> Hi Alex/Jasper,
>
> Just wanted to confirm with you guys on following stuff. Now i have to 
> create the one-to-many self referencing association. Following are the 
> details of table structure and annotations.
>
> *table: groups*
> id int(11) NOT NULL 
> name varchar(50) NOT NULL 
> parent_id int(11) NULL 
> icon_id int(11) NULL
>
> *table: group_members*
> int int(11) NOT NULL 
> group_id int(11) NOT NULL
> user_id int(11) NOT NULL 
> is_teacher int(11) NOT NULL
>
> *Annotations*
>
> *.....................groups.........................*
> /**
>  * @Entity @Table(name="groups")
>  **/
> class Group 
> {
> /**
>      * @Id @Column(type="integer") @GeneratedValue
>      * @var int
>      */
>     protected $id;
>
>     /**
>      * @Column(type="string")
>      * @var string
>      */
>     protected $name;
>
>     /**
>      * @OneToMany(targetEntity="Group", mappedBy="class")
>      **/
>     private $groups;
>
>     /**
>      * @ManyToOne(targetEntity="Group", inversedBy="groups")
>      * @JoinColumn(name="parent_id", referencedColumnName="id")
>      **/
>     private $class;
>
>     /**
>      * @Column(type="integer", nullable=true)
>      * @var integer
>      */
>     protected $icon_id;
>
>     public function __construct() {
>         $this->groups = new ArrayCollection();
>     }
>
> *........................group_members..........................*
> /**
>  * @Entity @Table(name="group_members")
>  **/
> class GroupMember
> {
> /**
>      * @Id @Column(type="integer") @GeneratedValue
>      * @var int
>      */
>     protected $id;
>
>     /**
>      * @ManyToOne(targetEntity="Group", inversedBy="group_members")
>      * @JoinColumn(name="group_id", referencedColumnName="id")
>      **/
>     private $group;
>
>     /**
>      * @ManyToOne(targetEntity="User", inversedBy="group_members")
>      * @JoinColumn(name="user_id", referencedColumnName="id")
>      **/
>     private $groupuser;
>
> I have to get list of all members by group id or name. Am unable to get it.
>
> Thank you,
> Swapna V
>
> On Sunday, March 30, 2014 9:15:29 PM UTC+5:30, Swapna V wrote:
>>
>> Hi,
>>
>> I am new to doctrine world. I have problem with understanding 
>> many-to-many associations. Following is my table structure:
>>
>> **users**
>>
>> id int(11) NOT NULL
>>
>> name varchar(50) NOT NULL
>>
>> role_id int(11) NOT NULL
>>
>> **roles**
>>
>> int int(11) NOT NULL
>>
>> role varchar(255) NOT NULL
>>
>> **relations**
>>
>> id int(11) NOT NULL
>>
>> name varchar(50) NOT NULL
>>
>> **relatives**
>>
>> id int(11) NOT NULL
>>
>> user_id int(11) NOT NULL
>>
>> relativeuser_id int(11) NOT NULL
>>
>> relation_id int(11) NOT NULL
>>
>> invitedby_id int(11) NULL
>>
>> according to above schema relatives columns user_id, relativeuser_id and 
>> invitedby_id are foreign key from users table. And relation_id is foreign 
>> key from relations table.
>>
>>
>> Please help me creating associations for this table. (if you give answer 
>> in yaml format will be helpful).
>>
>> Thank you,
>>
>> Swapna V
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to