Note that there are some explanatory texts on larger screens.

plurals
  1. POCakephp contain and belongsTo hasMany conditions
    text
    copied!<p>From the CakePHP manual:</p> <pre><code> Let's say you had a belongsTo relationship between Posts and Authors. Let's say you wanted to find all the posts that contained a certain keyword ("magic") or were created in the past two weeks, but you want to restrict your search to posts written by Bob: array ( "Author.name" =&gt; "Bob", "OR" =&gt; array ( "Post.title LIKE" =&gt; "%magic%", "Post.created &gt;" =&gt; date('Y-m-d', strtotime("-2 weeks")) ) ) </code></pre> <p>However, its not working for me. I've got Scrapes belongsTo Vargroup, and Vargroup hasMany Scrape. My scrapes table has a field vargroup_id</p> <p>When I do:</p> <pre><code>$this-&gt;Vargroup-&gt;contain('Scrape'); $this-&gt;Vargroup-&gt;find('first'); </code></pre> <p>I get:</p> <pre><code>Array ( [Vargroup] =&gt; Array ( [id] =&gt; 16950 [item_id] =&gt; 1056 [image] =&gt; cn4535d266.jpg [price] =&gt; 22.95 [instock] =&gt; 1 [timestamp] =&gt; 2012-10-29 11:35:10 ) [Scrape] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 18163 [item_id] =&gt; 1056 [vargroup_id] =&gt; 16950 [timestamp] =&gt; 2012-05-23 15:24:31 [instock] =&gt; 1 [price] =&gt; 22.95 ) ) ) </code></pre> <p>But when I do :</p> <pre><code>$this-&gt;Vargroup-&gt;contain('Scrape'); $this-&gt;Vargroup-&gt;find('first', array( 'conditions' =&gt; array( 'not' =&gt; array( array('Scrape.timestamp &gt;' =&gt; $today) ) ) )); </code></pre> <p>Im getting The following error with associated sql output</p> <pre><code>Warning (512): SQL Error: 1054: Unknown column 'Scrape.timestamp' in 'where clause' Query: SELECT `Vargroup`.`id`, `Vargroup`.`item_id`, `Vargroup`.`image`, `Vargroup`.`price`, `Vargroup`.`instock`, `Vargroup`.`timestamp` FROM `vargroups` AS `Vargroup` WHERE `Scrape`.`timestamp` = '2012-10-29 </code></pre> <p>It doesn't look like its binding the table at all.. Any help would be appreciated. Thanks </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