FriendsOfCake / crud-json-api

Build advanced JSON API Servers with almost no code.
https://crud-json-api.readthedocs.io/
MIT License
56 stars 32 forks source link

JsonApi Routes seem to interfere with bake migrations #141

Closed geoidesic closed 4 years ago

geoidesic commented 4 years ago

If I change my migration script (which I run with the --no-lock switch btw, as the app is pre-production) and then drop all tables, then try to run bin/cake migrations migrate --no-lock, it won't work. I get this error:

Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mnr_be_dev.devices' doesn't exist
In [/Users/me/project/vendor/cakephp/cakephp/src/Database/Schema/Collection.php, line 142]

If I then comment out the JsonApi routes, i.e. this line: JsonApiRoutes::mapModels($this->resources, $routes); the error goes away.

Any idea what's going on?

dakota commented 4 years ago

You need to wrap your JsonApiRoutes in a try...catch (I guess it could do that internally). JsonApiRoutes instantiates your table objects in order to generate all routes, so if the database table doesn't exist yet, it would break.