Im using a Model Post
. it doesn't have any associations. but for a paginated action i need to display the user name also, so used $this->Post->bindModel()
to attach User
model to the Posts. But i'm not getting the Users attached with the Post in the resulting query. The problem i think is the paginate
method initially makes a call like find('count')
to get the total no of results, so the bind is removed from there on. Have a look at my paginate
variable
var $paginate = array( 'limit'=>10, 'order'=>'created DESC' );
In the action
$this->Post->bindModel(array( 'belongsTo'=>array( 'User'=>array( 'className'=>'User', 'fields'=>'User.username,User.id', 'foreignKey'=>'user_id' ) ) )); $this->paginate('Post');