You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The generated models only include attributes and relationships that are included in the serializers for each model.
If a model exists, but does not have a serializer it will be skipped
Extra Attributes
In some cases you may want to allow attributes to be pushed to the API, but not serialized from the API. For instance
you need to push user.password, but you shouldn't have password in the user serializer. To include these
private attributes simply add a method in your seralizer called private_attributes
If you are using polymorphic relationships your serializer will have a line like:
belongs_to:commentable,:polymorphic=>true
You can define a method in the serlializer to define what the available types will be.
defcommentable_types[Article,Event,Photo]end
Usage
install initializers
$ rails g jsonapi_models:install
Currently this gem only works to output Angular Models for use with the angular2-jsonapi
First set the ng_output in initializers/jsonapi_models.rb
generate models:
$ rails g jsonapi_models:angular
Inspired by MOGenerator, two classes will be created for each model. The machine generated class includes all of
the attributes and relationships. This file will be overwritten every time you generate models.
The other class extends the machine generated class and you can put custom model
methods in there. This file will only be written once.
Output
For use with angular2-jsonapi, you should set config.ng_ouput equal to
MyAngularApp/src/app
Two directories will be created only if they don't exist: models and services
This will handle creating the necessary datastore class as well which will initialize and import all of your models