Skip to content

Instantly share code, notes, and snippets.

@simkimsia
Created November 2, 2014 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simkimsia/f0a2e4097f848066221b to your computer and use it in GitHub Desktop.
Save simkimsia/f0a2e4097f848066221b to your computer and use it in GitHub Desktop.
how to grab one side of many to many entities in Cake 3
<?php
// I have this in BookmarksController
// I am following the bookmarkr tutorial in http://book.cakephp.org/3.0/en/tutorials-and-examples/bookmarks/intro.html
/**
* Index view by tag method
*
* @return void
*/
public function index_by_tag($tag_id) {
$conditions = [
'Bookmarks.public' => true,
];
$this->paginate = [
'conditions' => $conditions,
'contain' => [
'Users' => function ($q) {
return $q
->select(['username', 'id']);
}
],
'order' => [
'Bookmarks.updated' => 'desc',
'Bookmarks.id' => 'desc'
]
];
$this->set('bookmarks', $this->paginate($this->Bookmarks));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment