Skip to content

Type only post requests#153

Merged
dgeb merged 4 commits intoJSONAPI-Resources:masterfrom
adamworrall:type-only-post-requests
Apr 8, 2015
Merged

Type only post requests#153
dgeb merged 4 commits intoJSONAPI-Resources:masterfrom
adamworrall:type-only-post-requests

Conversation

@adamworrall
Copy link
Copy Markdown
Contributor

First shot at addressing POST where the data object only contains a "type" member.

Relates to discussion in #151. Created resources with only "type" in the data don't get @save_needed set, so they never actually save the ActiveRecord model and they don't get a change to generate validation errors, leading to incorrect 201 status.

I've added an explicit check to Resource#change to save if the object is_new, but that's ugly. Any thoughts on where this should be fixed?

POST with only 'type' key is not triggering a save on the activerecord model, but no errors are reported. This leads to an incorrect 201 status.
Resource#create_model instantiates an activerecord model, but doesn't trigger a save. The save comes in _replace_fields, but if field_data[:attributes] is empty it never sets @save_needed.

I'm sure this isn't the best way to solve this issue, but it works for now.
@lgebhardt lgebhardt mentioned this pull request Apr 8, 2015
@dgeb dgeb merged commit d17ed92 into JSONAPI-Resources:master Apr 8, 2015
@jamonholmgren
Copy link
Copy Markdown
Contributor

👍

@adamworrall adamworrall deleted the type-only-post-requests branch April 6, 2016 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants