Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine won't add persist entity relationship
    primarykey
    data
    text
    <p>I have two entities, <code>View</code> and <code>Location</code></p> <p>Each <code>View</code> can have a <code>Location</code>.</p> <p>In my view I thus have:</p> <pre><code>class View { //..... Other Stuff..... /** * @ManyToOne(targetEntity="Location", inversedBy="views") **/ private $location; //...setters and getters.... public function setLocation($location){ $this-&gt;location = $location; } } </code></pre> <p>and then for my Location</p> <pre><code>class Location { //.....other stuff..... /** * @OneToMany(targetEntity="View", mappedBy="location") **/ private $views; public function __construct() { $this-&gt;created = $this-&gt;updated = new \DateTime("now"); $this-&gt;views = new \Doctrine\Common\Collections\ArrayCollection(); } // .... Getters and Setters .... } </code></pre> <p>But when I try and do this:</p> <pre><code>&lt;?php $this-&gt;pageview = $this-&gt;em-&gt;getRepository('Entities\View')-&gt;find(1); $this-&gt;location = $this-&gt;em-&gt;getRepository('Entities\Location')-&gt;find(1); $this-&gt;pageview-&gt;setLocation($this-&gt;location); $this-&gt;em-&gt;persist($this-&gt;pageview); $this-&gt;em-&gt;flush(); ?&gt; </code></pre> <p>Or even when I create new entities:</p> <pre><code>&lt;?php $pv = new Entities\Pageview; $lc = new Entities\Location; $this-&gt;em-&gt;persist($lc); $this-&gt;em-&gt;flush(); $pv-&gt;setLocation($lc); $this-&gt;em-&gt;persist($pv); $this-&gt;em-&gt;flush(); ?&gt; </code></pre> <p>Doctrine <em>never</em> sets the location_id in the database (it is always NULL).</p> <p>I've checked the SQL queries and they're not even being attempted at being set, all I'm getting is:</p> <pre><code>INSERT INTO View (field1, field2, created, updated) VALUES ('val1', 'val2', '2013-07-17T12:10:56+01:00', '2013-07-17T12:10:56+01:00') </code></pre> <p>No reference to locations whatsoever...The weird thing is I can update field1 and field2 fine...and all other relations are working throughout my application...I just can't get views and locations to work...</p> <p><strong>EDIT</strong></p> <p>I have the exact some code working now on another computer. I don't know why it wasn't working, but I just moved the files back and restarted my computer and now it is...cacheing problem I guess?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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