I have the user
object who has manytomany relation with Group
entity.
But i want that by default the user should be added to Group Group_User
which has id=4 in database.
Now how can i add that in User constructor
How can use query in Entity class
You can pass what you want in your User constructor. You'll have to pass it from your controller (where your queryManger is available).
In your controller:
$group_user = $this->getDoctrine()->getEntityManager()->getRepository("Bundle:Entity")->find(4);
$user = new User($group_user);
In your construct:
public function __construct(Group $group_user)
{
$this->$group = $group_user;
}
When you'll persist your user entity in the controller, the user and it's group relation will be directly saved.