Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First of all about your Model::save functions, for example:</p> <pre><code>public function save($data = NULL, $validate = true, $fieldList = array()) { $id = Post::find('first', array( 'fields' =&gt; array('id'), 'recursive' =&gt; -1, 'conditions' =&gt; array('external_post_id' =&gt; $data['external_post_id']) )); if( $id ) $data['id'] = $id['Post']['id']; pr($data); return parent::save($data, $validate, $fieldList); } </code></pre> <p>it prints $data in this way :</p> <pre><code>Array ( [id] =&gt; 3 //for example 3 [Post] =&gt; Array ( [external_post_id] =&gt; 12345 [sentiment_score] =&gt; 3.3 ) [URL] =&gt; Array ( [url] =&gt; http://test.com ) [Anchor] =&gt; Array ( [anchor] =&gt; Test Anchor ) ) </code></pre> <p>this $data is incorrect, the correct data is:</p> <pre><code> Array ( [Post] =&gt; Array ( [id] =&gt; 3 //for example 3 [external_post_id] =&gt; 12345 [sentiment_score] =&gt; 3.3 ) [URL] =&gt; Array ( [url] =&gt; http://test.com ) [Anchor] =&gt; Array ( [anchor] =&gt; Test Anchor ) ) </code></pre> <p>You must change your Model::save function this way:</p> <pre><code>public function save($data = NULL, $validate = true, $fieldList = array()) { $id = Post::find('first', array( 'fields' =&gt; array('id'), 'recursive' =&gt; -1, 'conditions' =&gt; array('external_post_id' =&gt; $data['external_post_id']) )); if( $id ) $data[$this-&gt;name]['id'] = $id['Post']['id']; return parent::save($data, $validate, $fieldList); } </code></pre> <p>second , you can't save this data with single save, you should save your data this way:</p> <pre><code>$postData = array ( 'Post' =&gt; array ( 'external_post_id' =&gt; 12345 'sentiment_score' =&gt; 3.3 ) ); $this-&gt;Post-&gt;save($data); $postUrlId = $this-&gt;PostsUrl-&gt;find('first', array( 'conditions' =&gt; array( 'post_id' =&gt; $this-&gt;Post-&gt;id ), 'fields' =&gt; array('id') )); $urlAnchorData = array( 'URL' =&gt; array ( 'url' =&gt; 'http://test.com' ), 'Anchor' =&gt; array ( 'anchor' =&gt; 'Test Anchor' ), 'PostsUrl' =&gt; array( 'id' =&gt; $postUrlId['PostsUrl']['id'] ) ); $this-&gt;PostsUrl-&gt;saveAll('$urlAnchorData'); </code></pre>
 

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