I have correctly set up a HABTM relationship between Post
and Tag
. When the user navigates to a URL like http://site.com/tag/test
I want to show all the posts tagged with test
.
Using the following code gets the tag information and all the posts which have that tag:
public function view($name) {
$this->set('tag', $this->Tag->findByName($name));
}
However, the posts it returns are not sorted by their created
column, they seem to be retrieved on a "first come first serve" basis. I tried doing this:
public function view($name) {
$this->set('tag', $this->Tag->findByName($name, array(
'order' => array('Post.created DESC')
)));
}
However that gave me an SQL error:
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Tag.' in 'field list'
SQL Query: SELECT DISTINCT
Tag
.` FROM
portfolio.
tagsAS
TagWHERE
Tag.
name` = 'test' LIMIT 1
Is there any way for me to order posts from newest to oldest in the query or do I have to reformat the result array in my controller?