Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to saveall() into two separate tables with several entries
    primarykey
    data
    text
    <p>Hey all. I can't for the life of me seem to get this blasted <code>saveall()</code> function to work. I told it was magical, but I must not have enough midichlorians or whatever fancy stuff it takes to get it sparkin'.</p> <p>So I've got four different tables--Questions, Comments, Employees, and Answers. Questions have many answers, and answers have one comment. Answers belong to Employees. Here's what's set up in my models:</p> <p><strong>Answer Model</strong></p> <pre><code>var $hasOne = array( 'Comment' =&gt; array( 'className' =&gt; 'Comment', 'foreignKey' =&gt; 'answer_id', 'conditions' =&gt; '', 'fields' =&gt; '', 'order' =&gt; '' ) ); var $belongsTo = array( 'Question' =&gt; array( 'className' =&gt; 'Question', 'foreignKey' =&gt; 'question_id', 'conditions' =&gt; '', 'fields' =&gt; '', 'order' =&gt; '' ), 'Employee' =&gt; array( 'className' =&gt; 'Employee', 'foreignKey' =&gt; 'employee_id', 'conditions' =&gt; '', 'fields' =&gt; '', 'order' =&gt; '' ) ); </code></pre> <p><strong>Comment Model</strong></p> <pre><code>var $validate = array( 'answer_id' =&gt; array( 'numeric' =&gt; array( 'rule' =&gt; array('numeric'), ), ), ); var $belongsTo = array( 'Answer' =&gt; array( 'className' =&gt; 'Answer', 'foreignKey' =&gt; 'answer_id', 'conditions' =&gt; '', 'fields' =&gt; '', 'order' =&gt; '' ) ); </code></pre> <p>When I run <code>saveall()</code> for my data, I'm getting an error saying that my answer_id for my comments are not numeric. Here's what my data tree is set up like that I'm trying to save (using <code>$this-&gt;Answer-&gt;saveall($this-&gt;data);</code>:</p> <pre><code>[Answer] =&gt; Array ( [1] =&gt; Array ( [question_id] =&gt; 1 [employee_id] =&gt; 14 [result] =&gt; 7 [unique_hash] =&gt; t9279kn7vh ) [3] =&gt; Array ( [question_id] =&gt; 3 [employee_id] =&gt; 14 [result] =&gt; 6 [unique_hash] =&gt; t9279kn7vh ) [4] =&gt; Array ( [question_id] =&gt; 4 [employee_id] =&gt; 14 [result] =&gt; 3 [unique_hash] =&gt; t9279kn7vh ) [5] =&gt; Array ( [question_id] =&gt; 5 [employee_id] =&gt; 14 [result] =&gt; 2 [unique_hash] =&gt; t9279kn7vh ) [6] =&gt; Array ( [question_id] =&gt; 6 [employee_id] =&gt; 14 [result] =&gt; 7 [unique_hash] =&gt; t9279kn7vh ) ) [Comment] =&gt; Array ( [1] =&gt; Array ( [user_id] =&gt; 14 [text] =&gt; test1 ) [3] =&gt; Array ( [user_id] =&gt; 14 [text] =&gt; test2 ) [4] =&gt; Array ( [user_id] =&gt; 14 [text] =&gt; test3 ) [5] =&gt; Array ( [user_id] =&gt; 14 [text] =&gt; test4 ) [6] =&gt; Array ( [user_id] =&gt; 14 [text] =&gt; test5 ) ) </code></pre> <p>Can anyone help me figure out what's wrong here? I appreciate the help.</p> <p><strong>EDIT</strong>: I've updated the $data array to have its keys start at zero with increments of one (i.e., <code>array(0=&gt;array(),1=&gt;array(),2=&gt;array());</code> etc.) and this has taken away the validation error, but the data still isn't saving.</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