title: how to check if value exists in table using cakephp
body: <p><strong>Edit - I fixed the original error, but now I still have one more</strong></p>
  
  <p>When I click on "Upvote" I get the message "vote could not be saved" message meaning that for whatever reason, it's not querying properly (otherwise it would see that there is no record saved). Also, I get an error saying "Undefined index" but I'm not sure what it's referring to.</p>
  
  <p>Here are my tables</p>
  
  <pre><code>Votes
  id |  user_id | vote
  
  Posts
  id |  title | body | created | modified | user_id | vote_total
  </code></pre>
  
  <p>This is one of the links to upvote found on posts/index.ctp</p>
  
  <pre><code>&lt;td&gt;&lt;?php echo $this-&gt;Html-&gt;link('Upvote', array('action' =&gt; 'vote', $post['Post']['id']))?&gt;
  </code></pre>
  
  <p>So, here's the vote function found in postscontroller.php</p>
  
  <pre><code>public function vote($id=null){
  
  $this-&gt;Post-&gt;Votes-&gt;recursive = 0;
  
  $this-&gt;Post-&gt;id = $id;
  $user = $this-&gt;Auth-&gt;User();
  $userid = $user['id'];
  $conditions = array('votes.id' =&gt; $id, 'votes.user_id' =&gt; $userid, 'votes.vote' =&gt; '1');
  
  $data = $this-&gt;Post-&gt;Votes-&gt;find('All' , array('conditions'=&gt;$conditions));
  
  if (isset($data) &amp;&amp; !empty($data)) {
      echo '&lt;p&gt;User have already give a vote!&lt;/p&gt;';
  } else {
  
      if($this-&gt;Post-&gt;Votes-&gt;validates()){
          if ($this-&gt;Post-&gt;Votes-&gt;save($this-&gt;request-&gt;data)) {
                  $this-&gt;Session-&gt;setFlash(__('The vote has been saved'));
          } else {
                  $this-&gt;Session-&gt;setFlash(__('The vote could not be saved. Please, try again.'));
          }
      }   
  }
  }
  </code></pre>
  
  <p>This relation is found in my Post.php model. </p>
  
  <pre><code>public $hasMany = array(
      'Votes' =&gt; array(
          'foreignKey' =&gt; 'id'
          )
      );
  </code></pre>
  
  <p>This relation is found in User.php model</p>
  
  <pre><code>public $hasMany = array(
      'Posts' =&gt; array(
          'className'  =&gt; 'Post'
          )
      );
  </code></pre>