Note that there are some explanatory texts on larger screens.

plurals
  1. POCakephp - saveAll and beforeSave
    text
    copied!<p>Since CakePHP is updated to 2.3.5, I have problem to save data. I don't want to save datas who contains no price.</p> <p>My method beforeSave in my model looks like this :</p> <pre><code>public function beforeSave($options = array()){ if(empty($this-&gt;data['MyModel']['price'])){ unset($this-&gt;data['MyModel']); } return true; } </code></pre> <p>Since my update, i've found this in /lib/Model/Model.php (l. 1751)</p> <pre><code>if ($success &amp;&amp; $count === 0) { $success = false; } </code></pre> <p>If i comment this 3 lines my problem is solved. Do you know a method in my beforeSave who don't block my saving ?</p> <p>If i use data validation, all my datas are not saved with my saveAll.</p> <p>Exemple model "Option" validator:</p> <pre><code>public $validate = array( 'prix' =&gt; array( 'rule' =&gt; 'notEmpty' ) ); </code></pre> <p>Exemple datas to save :</p> <pre><code>array( 'Commande' =&gt; array( 'nature_commande' =&gt; '0', 'base_id' =&gt; '1', 'nom' =&gt; 'Test', 'chef_id' =&gt; '531', ), 'Option' =&gt; array( (int) 0 =&gt; array( 'prix' =&gt; '5456' ), (int) 1 =&gt; array( 'prix' =&gt; '45645' ), (int) 3 =&gt; array( 'prix' =&gt; '' ) ) </code></pre> <p>saveAll in my Controller "Commande" (return false):</p> <pre><code>debug($this-&gt;Commande-&gt;saveAll($this-&gt;request-&gt;data, array('validate' =&gt; 'first'))); </code></pre> <p>I would like my datas be saved out of the last row in my Model "Options" => 3. I can use foreach in my controler to delete the blank row but can i make it better ?</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