I have a User model and a serializer for it. I’d like to be able to determine if I am dealing with a new user (i.e. POST) or an existing one (i.e. PATCH). The reason is because there is an attribute (currentPassword) that I’d like to yank out for a new user before sending the attributes to the server.
This seems like it should be simple, but I’ve googled and checked the API docs for DS.JSONAPISerializer and can’t see how to make this determination.
The serialize method takes a snapshot, and the snapshot has a reference to the record, so I’d think you should be able to do something like the following in the serialize method:
if(snapshot.record.get('isNew')) {
...
}
Just tested that it would work in some of my code and it seems to. As for exactly how to strip that field there are a variety of ways you could approach it so that’s up to you.