Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's try again. This time, I'm working directly from the <strong>Entries</strong> controller.</p> <pre><code>/** * Unbind the existing relationship with Feed */ $this-&gt;Entry-&gt;unbindModel(array( 'belongsTo' =&gt; array('Feed') )); /** * Explicitly bind of the 'parent' models */ $this-&gt;Entry-&gt;bindModel(array( 'hasOne' =&gt; array( 'Feed' =&gt; array( 'foreignKey' =&gt; false, 'conditions' =&gt; array('Feed.id = Entry.feed_id') ), 'Feedfolder' =&gt; array( 'foreignKey' =&gt; false, 'conditions' =&gt; array('Feedfolder.id = Feed.feedfolder_id') ), 'User' =&gt; array( 'foreignKey' =&gt; false, 'conditions' =&gt; array('User.id = Feedfolder.user_id') ) ) )); /** * Find the entries that are unread and belong to the current user * and then Group by Feed.id */ $unread = $this-&gt;Entry-&gt;find('all', array( 'fields' =&gt; array( 'Feed.Title', 'COUNT(Entry.id) AS UnreadCount' ), 'conditions' =&gt; array( 'Entry.read' =&gt; 0, 'User.id' =&gt; $this-&gt;Auth-&gt;user('id') ), 'group' =&gt; array( 'Feed.id' ) )); </code></pre> <p>What's happening here?</p> <p>Firstly, we unbind the <strong>Feed</strong> model.</p> <p>Secondly, we explicitly bind the <strong>Entry</strong> model with <strong>Feed</strong>, <strong>Feedfolder</strong> and <strong>User</strong> models. This prevents Cake trying to use it's automagical goodness (which is still great btw).</p> <p>Lastly, we call a find on the <strong>Entry</strong> model and set up our required conditions: <em>entries that are unread</em> and <em>belong to the current user</em>. We then group it all by the <em>Feed.id</em>.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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