Answer the question
In order to leave comments, you need to log in
The repository stopped working, the entity constructor is not called?
Dear Toasters!
Help to solve a problem - the third day I fight! Started learning symfony. The task is as follows:
Entity 1 - sad (id, title)
Entity 2 - me(id, val)
Relationship: for each entity 1 there are many entities 2.
I do this:
Entity 1 - sad
<?php
namespace Stocker\StockBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass="Stocker\StockBundle\Entity\Repository\SadRepository")
* @ORM\Table(name="sad")
*/
class Sad
{
public function __construct()
{
$this->mes=new ArrayCollection();
}
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $title;
/**
* @ORM\OneToMany(targetEntity="Me", mappedBy="Sad")
*/
private $mes;
<?php
namespace Stocker\StockBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="Stocker\StockBundle\Entity\Repository\Sad1Repository")
* @ORM\Table(name="me")
*/
class Me
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $val;
/**
* @ORM\ManyToOne(targetEntity="Sad", inversedBy="mes")
* @ORM\JoinColumn(name="sad_id", referencedColumnName="id")
*/
private $sad;
<?php
namespace Stocker\StockBundle\Entity\Repository;
/**
* SadRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class SadRepository extends \Doctrine\ORM\EntityRepository
{
public function getSad(){
$qb=$this->createQueryBuilder('f')
->select('f');
return $qb->getQuery()->getResult();
}
}
array:2 [▼
0 => Sad {#458 ▼
#id: 1
#title: "asdf"
-mes: PersistentCollection {#475 ▼
-snapshot: []
-owner: Sad {#458}
-association: array:15 [ …15]
-em: EntityManager {#106 …11}
-backRefFieldName: "Sad"
-typeClass: ClassMetadata {#456 …}
-isDirty: false
#collection: ArrayCollection {#484 ▼
<b> -elements: []</b>
}
<b> #initialized: false</b>
}
}
1 => Sad {#482 ▶}
]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question