-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Has_one relation doesn't check for existence #70
Comments
I was just starting to look at this. What was the resolution? |
I reworked something on my end so it didn't matter anymore. I didn't want to create more work if no one else was complaining. |
Ok, thanks. I'll still take a look at it then. |
Were you seeing the normal Rails behavior of not validating the existence of a related object? If so, there are a few ways you can fix that. The first is using a validation gem such as https://github.com/perfectline/validates_existence, which I have not tested. Another way would be to put foreign key constraints on the database and handle the error when the resource is saved. And finally you could override the def verify_key(key, context = nil)
#try to load a resource to make sure it exists. Will raise a JSONAPI::Exceptions::RecordNotFound if the resource is not found
find_by_key(key, context: context)
return key
end I personally like overriding the One final note, using the |
Okay. Thanks very much! I added the database constraint. |
I'm not sure if I'm doing something wrong but I have a has_one relationship in one of my resources and if I create an instance using the create route and put in a links parameter. It doesn't check if the associated record exists before retrieving it.
The text was updated successfully, but these errors were encountered: