diff --git a/package.json b/package.json index 78cb67c..d56e3b2 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "dependencies": { "change-case": "^3.0.0", "i": "^0.3.5", + "inflect": "^0.4.0", "jsonapi-serializer": "^3.5.0", "lodash.keysin": "^4.2.0", "lodash.mapkeys": "^4.6.0", diff --git a/src/JsonApiView.js b/src/JsonApiView.js index cc5833a..3fcf15f 100644 --- a/src/JsonApiView.js +++ b/src/JsonApiView.js @@ -26,6 +26,10 @@ class JsonApiView { this.use = use; } + static typeForAttribute(attribute, record) { + return i.dasherize(i.underscore(attribute)); + } + get primaryKey() { return 'id'; } @@ -75,6 +79,8 @@ class JsonApiView { } }); + obj.typeForAttribute = this.constructor.typeForAttribute; + obj.meta = meta || {}; return obj;