Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot save a Doctrine_Collection
    primarykey
    data
    text
    <p>I am using Docrine 1.2 with Zend Framework and trying to save a Doctrine Collection.</p> <p>I am retrieving my collection from my table class with the following code.</p> <pre><code>public function getAll() { return $this-&gt;createQuery('e') -&gt;orderBy('e.order ASC, e.eventType ASC') -&gt;execute(); } </code></pre> <p>I also have the following class to reorder the above event records.</p> <pre><code>class Admin_Model_Event_Sort extends Model_Abstract { /** * Events collection * @var Doctrine_Collection */ protected $_collection = null; public function __construct() { $this-&gt;_collection = Model_Doctrine_EventTypesTable::getInstance()-&gt;getAll(); } public function save($eventIds) { if ($this-&gt;_collection instanceof Doctrine_Collection) { foreach ($this-&gt;_collection as $record) { $key = array_search($record-&gt;eventTypeId, $eventIds); if ($key !== false) { $record-&gt;order = (string)$key; } } return $this-&gt;_saveCollection($this-&gt;_collection); } else { return false; } } } </code></pre> <p>The _saveCollection method above is as follows</p> <pre><code>/** * Attempts to save a Doctrine Collection * Sets the error message property on error * @param Doctrine_Collection $collection * @return boolean */ protected function _saveCollection(Doctrine_Collection $collection) { try { $collection-&gt;save(); return true; } catch (Exception $e) { $this-&gt;_errorMessage = $e-&gt;getMessage(); OpenMeetings_Logger_ErrorLogger::write('Unable to save Doctrine Collection'); OpenMeetings_Logger_ErrorLogger::vardump($this-&gt;_errorMessage); return false; } } </code></pre> <p>The event id's in the above save method is simply an enumerated array of event id's, I am using the keys of the array to set the sort order of the events using the order field. If I do a var_dump of the collection to an array ($this->_collection->toArray()) I get the correct data. However when I attempt to save the collection I get the following error.</p> <p>"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order = '0' WHERE eventtypeid = '3'' at line 1"</p> <p>Is there anyway I can get Doctrine to expand on this error, the full SQL statement would be a start, also if anyone knows as to why this error is occuring then that would be very helpful.</p> <p>Many thanks in advance</p> <p>Garry</p> <p>EDIT</p> <p>I have modified my above code to try to work one record at a time but I still get the same problem.</p> <pre><code>public function save($eventIds) { foreach ($eventIds as $key =&gt; $eventId) { $event = Model_Doctrine_EventTypesTable::getInstance()-&gt;getOne($eventId); $event-&gt;order = (string)$key; $event-&gt;save(); } } </code></pre>
    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.
    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