On my sf 2.8 project got the following entity with self relation, used to store tourist destinations, for example a parent could be Caribe, children Jamaica, and children Kingston
class Destination
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
* @Assert\NotBlank()
*/
private $name;
/**
* @var \Application\ModelBundle\Entity\Destination
*
* @ORM\ManyToOne(targetEntity="Application\ModelBundle\Entity\Destination", inversedBy="children")
* @ORM\JoinColumn(name="parent", referencedColumnName="id", onDelete="cascade")
*/
private $parent;
/**
* @var \Application\ModelBundle\Entity\Destination
*
* @ORM\OneToMany(targetEntity="Application\ModelBundle\Entity\Destination", mappedBy="parent", cascade={"persist", "remove"})
*/
private $children;
/**
* @var \Application\ModelBundle\Entity\User
*
* @ORM\ManyToOne(targetEntity="Application\ModelBundle\Entity\User", inversedBy="destinations")
* @ORM\JoinColumn(name="user", referencedColumnName="id", onDelete="cascade")
* @Assert\Type(type="Application\ModelBundle\Entity\User")
*/
private $user;
/**
* @var \Application\ModelBundle\Entity\Hotel
*
* ORM\OneToMany(targetEntity="Application\ModelBundle\Entity\Hotel", mappedBy="touristDestination", cascade={"persist"})
*/
private $hotels;
}
Everything works well with few records, but when i populate the entity or table with all records from a country for example (12000 records), system run out of memory, it's impossible do something, and throws this error
OutOfMemoryException in JsonSerializationVisitor.php line 29:
Error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 10489856 bytes)
in JsonSerializationVisitor.php line 29
i'm running a command to load destinations from xls file, it run out of memory, never finish, and later i'm not able to do any action on my project
Maybe the problem is that symfony loads all related objects and it collapse, any ideas how to solve it?