-
Notifications
You must be signed in to change notification settings - Fork 182
find with nil attribute #329
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
Comments
Can you tell me a little bit more about what you're seeing? Does it hit |
@gaorlov But the problem can be a critical for specific scenarios: 1 So, when we searching for a single resource by primary key, we typically write the things like product = Product.find(id).first 2 3 Lets sum 1 + 2 + 3 - in case if id is blank, we will silently receive the Even worse, Once again - at the moment we receive the random resource when searching by blank primary key O_o That is absolutely not what we expect to reach. That can give us a tons of unexpected and unexplained effects all around the system. To fix that we patched the builder this way: class MyBuilder < JsonApiClient::Query::Builder
def find(args={}, collection: false)
raise ::JsonApiClient::Errors::NotFound if !collection && args.blank?
super(args)
end
def to_a
@to_a ||= find(collection: true)
end
alias all to_a
end Please let me know is that looks good enough for PR :) |
In case of singleton api endpoint current behaviour is correct. |
@senid231 Roger, just thought the same |
@stokarenko marvelous. I really appreciate you doing this work! I left one small comment, but it looks solid otherwise. Thanks! |
@gaorlov force pushed with additional test ) |
|
Hello, so I have a concern related to the find method. I noticed that if for some reason the specified id for model record is nil and passed into the api find method it will interpolate the nil on the end of the query string when performing the request. This means the index action instead of the show action is called and returns the entire collection of specified model records. Wouldn't it be ideal for the api client lib to handle this nil behavior and throw a client error (argument error)? I would really like some feedback on this. I would prefer not to have to...
Thanks, and TGIF :)
The text was updated successfully, but these errors were encountered: