Your Location is: Home > Php

Doctrine result giving infinite loop

From: Vaduz View: 2534 Marcelo Custódio 

Question

Here are my two classes

class Product extends BaseModel{

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue
 */
protected $id;

/**
 * @ORM\Column(type="string") 
 */
protected $name;

/**
 * @ORM\Column(type="string")
 * @var string
 */
protected $description;

protected $created;

/**
 * @ORM\Column(type="string")
 * @var string
 */
protected $status;

/**
 * @ORM\Column(type="decimal", precision=5, scale=4)
 * @var float
 */
protected $price;

/**
 * @ORM\ManyToOne(targetEntity="Category")
 * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
 */
private $category;

}

and

class Category extends BaseModel {

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue
 */
protected $id;

/**
 * @ORM\Column(type="string") 
 */
protected $category;}

as I perform this

$fullyQualifiedClassName = '\\System\\App\\Model\\Product';
    $object = new $fullyQualifiedClassName();
    $objectRepository = $this->entityManager->getRepository($fullyQualifiedClassName);
    $results = $objectRepository->findAll();
    print_r($results);

the application enters an infinite loop giving for each product its category associated and for each category its products and so on until the app breaks.

how can I fix this ?

thanks in advance.

Best answer