Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine 2 - strange findBy() function
    text
    copied!<p>i tried to fetch data from database with Doctrine 2, but I have problem with findBy() function.</p> <p>I have entity <strong>User</strong>:</p> <pre><code>/** * @ORM\id * @ORM\generatedValue * @ORM\column(type="integer") */ private $id; /** * @ORM\column(type="string", length=32, unique=true) */ private $user; </code></pre> <p>And entity <strong>UserList</strong>:</p> <pre><code>/** * @ORM\id * @ORM\generatedValue(strategy="NONE") * @ORM\oneToOne(targetEntity="User") * @ORM\joinColumn(name="user_id", referencedColumnName="id") */ private $id; /** * @ORM\oneToOne(targetEntity="User") * @ORM\joinColumn(name="parent_id", referencedColumnName="id") */ private $parent = null; </code></pre> <p>I have table with data:</p> <pre><code>Users: +----+------+ | id | user | +----|------+ | 1 | John | | 2 | Jane | | 3 | Doe | +----+------+ UsersList (id 3 have two parents): +---------+-----------+ | user_id | parent_id | +---------|-----------+ | 1 | NULL | | 2 | NULL | | 3 | 1 | | 3 | 2 | +---------+-----------+ </code></pre> <p>I want to get Doe's (id 3) parents:</p> <pre><code> $user = $this-&gt;entityManager-&gt;getRepository('User')-&gt;findByUser('Doe'); $user_parents = $this-&gt;entityManager-&gt;getRepository('UserList')-&gt;findById($user); foreach($user_parents as $parent) { var_dump($parent); } </code></pre> <p>Return:</p> <pre><code> UserList(2) { id private =&gt; 3 parent private =&gt; 1 } UserList(2) { id private =&gt; 3 parent private =&gt; 1 //this should be 2 } </code></pre> <p>Where is the problem? Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload