Closed geoidesic closed 4 years ago
Also a question: why is it generating dishes_restaurants
relationships, when this is already covered by dishes
and restaurants
?
Definitely something not right there. Could you paste the output of cake routes
?
The issues seems to be either the incorrect routes are being generated, or the incorrect routes are being used.
Ok so firstly the associations...
On DishesTable
$this->belongsToMany('Restaurants', [
'foreignKey' => 'dish_id',
'targetForeignKey' => 'restaurant_id',
'joinTable' => 'dishes_restaurants',
]);
On RestaurantsTable
$this->belongsToMany('Dishes', [
'foreignKey' => 'restaurant_id',
'targetForeignKey' => 'dish_id',
'joinTable' => 'dishes_restaurants',
]);
The DishesRestaurantsTable
generated by bake also has these associations:
$this->belongsTo('Restaurants', [
'foreignKey' => 'restaurant_id',
'joinType' => 'INNER',
]);
$this->belongsTo('Dishes', [
'foreignKey' => 'dish_id',
'joinType' => 'INNER',
]);
Then the output from cake routes
+-------------------------------------+------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+
| Route name | URI template | Defaults |
+-------------------------------------+------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+
| schema:list | /schema | {"_method":"GET","action":"list","controller":"Schema","plugin":null} |
| schema:_controller:view | /schema/{controller} | {"_method":"GET","action":"view","plugin":null,"prefix":"Schema"} |
| ping | /api/ping | {"_method":"GET","action":"index","controller":"Pings","plugin":null,"prefix":"Api"} |
| api:pings:index | /api/ping | {"_method":"OPTIONS","action":"index","controller":"Pings","plugin":null,"prefix":"Api"} |
| api:restaurants:index | /api/restaurants | {"_method":"GET","action":"index","controller":"Restaurants","plugin":null,"prefix":"Api"} |
| api:restaurants:add | /api/restaurants | {"_method":"POST","action":"add","controller":"Restaurants","plugin":null,"prefix":"Api"} |
| api:restaurants:view | /api/restaurants/:id | {"_method":"GET","action":"view","controller":"Restaurants","plugin":null,"prefix":"Api"} |
| api:restaurants:edit | /api/restaurants/:id | {"_method":["PUT","PATCH"],"action":"edit","controller":"Restaurants","plugin":null,"prefix":"Api"} |
| api:restaurants:delete | /api/restaurants/:id | {"_method":"DELETE","action":"delete","controller":"Restaurants","plugin":null,"prefix":"Api"} |
| api:restaurants:relationships | /api/restaurants/:restaurant_id/relationships/dishes | {"_method":"PATCH","action":"relationships","controller":"Restaurants","plugin":null,"prefix":"Api","type":"Dishes"} |
| api:restaurants:relationships | /api/restaurants/:restaurant_id/relationships/dishes | {"_method":"POST","action":"relationships","controller":"Restaurants","plugin":null,"prefix":"Api","type":"Dishes"} |
| api:restaurants:relationships | /api/restaurants/:restaurant_id/relationships/dishes | {"_method":"DELETE","action":"relationships","controller":"Restaurants","plugin":null,"prefix":"Api","type":"Dishes"} |
| api:restaurants:relationships | /api/restaurants/:restaurant_id/relationships/dishes | {"_method":"GET","action":"relationships","controller":"Restaurants","plugin":null,"prefix":"Api","type":"Dishes"} |
| CrudJsonApi.Restaurants:Dishes | /api/restaurants/:restaurant_id/dishes | {"_method":"GET","action":"index","controller":"Dishes","from":"Restaurants","plugin":null,"prefix":"Api","type":"Dishes"} |
| api:dishes:index | /api/dishes | {"_method":"GET","action":"index","controller":"Dishes","plugin":null,"prefix":"Api"} |
| api:dishes:add | /api/dishes | {"_method":"POST","action":"add","controller":"Dishes","plugin":null,"prefix":"Api"} |
| api:dishes:view | /api/dishes/:id | {"_method":"GET","action":"view","controller":"Dishes","plugin":null,"prefix":"Api"} |
| api:dishes:edit | /api/dishes/:id | {"_method":["PUT","PATCH"],"action":"edit","controller":"Dishes","plugin":null,"prefix":"Api"} |
| api:dishes:delete | /api/dishes/:id | {"_method":"DELETE","action":"delete","controller":"Dishes","plugin":null,"prefix":"Api"} |
| api:dishes:relationships | /api/dishes/:dish_id/relationships/restaurants | {"_method":"PATCH","action":"relationships","controller":"Dishes","plugin":null,"prefix":"Api","type":"Restaurants"} |
| api:dishes:relationships | /api/dishes/:dish_id/relationships/restaurants | {"_method":"POST","action":"relationships","controller":"Dishes","plugin":null,"prefix":"Api","type":"Restaurants"} |
| api:dishes:relationships | /api/dishes/:dish_id/relationships/restaurants | {"_method":"DELETE","action":"relationships","controller":"Dishes","plugin":null,"prefix":"Api","type":"Restaurants"} |
| api:dishes:relationships | /api/dishes/:dish_id/relationships/restaurants | {"_method":"GET","action":"relationships","controller":"Dishes","plugin":null,"prefix":"Api","type":"Restaurants"} |
| CrudJsonApi.Dishes:Restaurants | /api/dishes/:dish_id/restaurants | {"_method":"GET","action":"index","controller":"Restaurants","from":"Dishes","plugin":null,"prefix":"Api","type":"Restaurants"} |
| api:settings:index | /api/settings | {"_method":"GET","action":"index","controller":"Settings","plugin":null,"prefix":"Api"} |
| api:settings:add | /api/settings | {"_method":"POST","action":"add","controller":"Settings","plugin":null,"prefix":"Api"} |
| api:settings:index | /api/settings | {"_method":"OPTIONS","action":"index","controller":"Settings","plugin":null,"prefix":"Api"} |
| api:_controller:index | /api/{controller} | {"action":"index","plugin":null,"prefix":"Api"} |
| api:_controller:_action | /api/{controller}/{action}/* | {"action":"index","plugin":null,"prefix":"Api"} |
| customer:pages:display | /customer | {"0":"home","action":"display","controller":"Pages","plugin":null,"prefix":"Customer"} |
| customer:pages:display | /customer/pages/* | {"action":"display","controller":"Pages","plugin":null,"prefix":"Customer"} |
| customer:_controller:index | /customer/{controller} | {"action":"index","plugin":null,"prefix":"Customer"} |
| customer:_controller:_action | /customer/{controller}/{action}/* | {"action":"index","plugin":null,"prefix":"Customer"} |
| customer:_controller:_action | /customer/{controller}/{action} | {"action":"index","plugin":null,"prefix":"Customer"} |
| device/customer:pages:display | /device/customer | {"0":"home","action":"display","controller":"Pages","plugin":null,"prefix":"Device\/customer"} |
| device/customer:pages:display | /device/customer/pages/* | {"action":"display","controller":"Pages","plugin":null,"prefix":"Device\/customer"} |
| device/customer:_controller:index | /device/customer/{controller} | {"action":"index","plugin":null,"prefix":"Device\/customer"} |
| device/customer:_controller:_action | /device/customer/{controller}/{action}/* | {"action":"index","plugin":null,"prefix":"Device\/customer"} |
| quasaradmin._controller:index | /quasar-admin/{controller} | {"action":"index","plugin":"QuasarAdmin"} |
| quasaradmin._controller:_action | /quasar-admin/{controller}/{action}/* | {"action":"index","plugin":"QuasarAdmin"} |
| quasaradmin._controller:index | /quasar-admin/{controller} | {"action":"index","plugin":"QuasarAdmin"} |
| quasaradmin._controller:_action | /quasar-admin/{controller}/{action}/* | {"action":"index","plugin":"QuasarAdmin"} |
+-------------------------------------+------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+
btw I’ve updated the OP with extra notes, highlighting what I think is a second problem with links
.
With the following schemas:
And standard baking. Using routes like so:
The route to get dishes related to a given restaurant would be:
This produces JSON:API output like so:
I've highlighted the problems with
<--- PROBLEM
in the output.PROBLEM 1 – These links, if followed, display ALL dishes, not those associated to Restaurants. Is this expected? PROBLEM 2 – These links, if followed produce an error:
I have tested this with normal id's (i.e. without using
uuid
in the schema and URLs) and I get the same issue.The error is because there is no
type
placeholder part of the URL. My thoughts are that these URLs are malformed. What does the JSON:API spec say about them?