ethanresnick / json-api

Turn your node app into a JSON API server (http://jsonapi.org/)
GNU Lesser General Public License v3.0
268 stars 41 forks source link

Multi word model name #135

Closed EmirGluhbegovic closed 6 years ago

EmirGluhbegovic commented 6 years ago

Hey there,

I have a model which is named AreaOfOperation. It seems for the mongoose adapter to register it I have to set the registry key to 'area-of-operation' for it to identify it, if I then set the URL types to either AreaOfOperation or area-of-operation, I keep getting an error message of '... is not a valid type'. I am not sure how to handle multi word model names, any suggestions?

ethanresnick commented 6 years ago

JSON:API type names are plural by convention (see examples on jsonapi.org), and I think that's what the registry's expecting. So try registering it with the key "area-of-operations" and see if that works. (If that's not an acceptable name, the MongooseAdapter is supposed to let you customize the pluralization rules, though, looking at the code, I'm not 100% sure that's working, so let's dig into that only if needed.)

EmirGluhbegovic commented 6 years ago

Thanks, so yo update what works for me is: The actual schema name i make AreaOfOperations (think mongoose or mongo then lowercases it anyway) Then the model reference for the adapter i call AreaOfOperation The registry key I call 'area-of-operation': The routes i call area-of-operations then it all works, the tricky gotcha was having to hyphenate the registry key and the routes but not the model key reference