Nept
Nept

Reputation: 103

ManyToMany doctrine relation with FOSUserBundle

I would like to make a relationship ManyToMany with two entity:

For the moment, I'm doing this in "MyNamespace/Userbundle/Entity/User.php" :

/**
 * @ORM\ManyToMany(targetEntity="\MyNamespace\WebsiteBundle\Entity\Categorie", inversedBy="users")
 * @ORM\JoinTable(name="user_has_categories")
 */
private $categories;

public function __construct()
{
    parent::__construct();
    $this->categories = new \Doctrine\Common\Collections\ArrayCollection();
}

And this in "MyNameSpace/WebsiteBundle/Entity/Categorie.php" :

/**
 * @ORM\ManyToMany(targetEntity="\MyNameSpace\UserBundle\Entity\User", mappedBy="categories")
 */
 private $users;

 public function __construct()
 {
   $this->users = new \Doctrine\Common\Collections\ArrayCollection();
 }

When I run the doctrine command for create the table with the reationship, everything is OK.

But when I do a var_dump($this->getUser()); in my default controller (for exemple), I have an infinite loop that crashes my browser. This effect no longer appears when I delete the relationship in my User entity ...

That would have an idea where this problem may be?

I turn with php 5.4.9 on ubuntu

Thank's :)

Upvotes: 2

Views: 591

Answers (1)

xiidea
xiidea

Reputation: 3394

Use

Doctrine\Common\Util\Debug::dump()

Instead of var_dump

-Updated-

Why Debug::dump() works but var_dump doesn't:

Doctrine\Common\Util\Debug::dump() accept second parameter maxDepth with default value = 2 to limit the nested reference to two level. You can pass this value as you like.

Upvotes: 3

Related Questions