I am trying to configure CakePHP to act as a REST API for an app i'm writing.
I have 3 tables:
dishes {
id,
name,
description
}
users {
id,
name,
email
}
dishes_users {
id,
user_id,
dish_id
}
I would like it so that when someone visits /users/1.xml, the data that gets returns is just the list of 'dishes' that a user has in the 'dishes_users' table, i dont want anything from users or dishes_users to be in there, just the id, name, and description of the dishes table.
in the end the xml structure has to be:
<dishes>
<dish id="1" name="whatever" description ="This is a description"/>
<dish id="2" name="whatever" description="This is another description"/>
</dishes>
This is currently the relationship i am using in the users model:
var $hasAndBelongsToMany = array(
"Dish" => array(
'className' => 'Dish',
'joinTable' => 'dishes_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'dish_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
));
In the controller i have:
function view($id) {
$dishes = $this->User->findAllById($id);
$this->set(compact('beers'));
}
This gives me what i want, but it also gives me a lot of stuff i don't want. All i need is the list of dishes.
Thanks for any help, this has been driving me nuts.