Created
November 2, 2014 05:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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