Closed maximderbin closed 7 years ago
@maximderbin thanks for the PR, I never actually got around to using rom-http beyond a simple PoC that only dealt with reads, sorry I missed that.
I'm not sure this should be handled implicitly in Command#execute
TBH, it could mess with peoples data and cause unexpected errors, say if a command is expected to return a multi-dimensional array, this could be done in the response handler with something like:
class ResponseHandler
def call(response, dataset)
if %i(post put patch).include?(dataset.request_method)
JSON.parse(response, symbolize_names: true)
else
Array([JSON.parse(response, symbolize_names: true)]).flatten
end
end
end
Let me know what you think.
cc: @solnic @cflipse
@AMHOL Yep I like it better. Do you want me to update usage examples then?
I'm also just paying around with it as POC. Just trying to break it haha 😆 Looking in potential replacing nasty her
with rom-http
@maximderbin that would be great.
You're doing a good job so far :wink: lol
Interesting, first time I've heard of her
Gonna close this PR since we agree on the other solution
@AMHOL https://github.com/remiprev/her it's ORM over http. Like https://github.com/rails/activeresource but a liittle bit better. But too much buggy and too much metaprogramming in sources. And you can't combine AR and her. ROM looks much more appropriate for this
Description:
relation.insert
always return array as we doArray([JSON.parse(response.body, symbolize_names: true)]).flatten
inResponseHandler#call
This is why
Command::Create#execute
results in something like:[[{id: 1, foo: 'bar'}]]
.This behaviour brakes command composition and rom-sql associations
Example: