I'm having trouble creating pagination using the HABTM relationship. First, tables and relationships:
requests (id, to_location_id, from_location_id)
locations (id, name)
items_locations (id, item_id, location_id)
items (id, name)
Thus, the request has a location where the request comes from and a location to which the request is sent. On this issue, only the "location" bothers me.
Request --belongsTo--> Location* --hasAndBelongsToMany--> Item
(* as "ToLocation")
In my RequestController, I want to split pages into all the elements in a ToLocation request.
var $paginate = array(
'Item' => array(
'limit' => 5,
'contain' => array(
"Location"
)
)
);
$locationId = 21;
$items = $this->paginate('Item', array(
"Location.id" => $locationId
));
And this does not work, because it generates this SQL:
SELECT COUNT(*) AS count FROM items Item WHERE Location.id = 21
I can't figure out how to make it actually use the contain argument $paginate...
Any ideas?
nickf source
share