So, what I have is a page which displays a post. Posts are gathered into projects. And, on this page, in addition to the post, I’ld to display the previous and next post of the same project. So, I have this in my controller :
$this->set("post", $this->Post->find("first", array("conditions" => array("Post.id" => $id), "contain" => array("User", "Project", "Project.Post" => array("id", "image", "title"), "Comment", "Comment.User" => array("id", "username", "mail"), "Comment.User.Post" => array("id", "image", "title")))));
$this->set("neighbors", $this->Post->find("neighbors", array("field" => "id", "value" => $id)));
The problem is that it get the previous and next post from all the post, not only the ones of the same project.
So, if you could helping me a bit 🙂
I’m assuming Post belongsTo Project and Project hasMany Post.
You would just need to add an extra condition:
I haven’t tried it, but looking at the source, findNeighbors does honor the
conditionskey.