Thanks Dave.

Maybe I expressed myself a bit unclearly. I'm not trying to reinvent SQL or 
create a new database implementation, that's insane! The API I'm building* 
is* RESTful of course. I don't have a problem of *querying models* per se, 
that's done with RESTful routing as it should be done. What I'm after is a 
way to do more complex *filtering* of the result set using query parameters 
than what ActiveRecord now supports. 

As of now a request like this

GET /api/users?name=Doris

works fine since I can filter the query parameters through params.permit 
and throw them into User.where(params) or something to that effect. 

However, the ActiveRecord Query Interface doesn't have that elaborate 
support for hash conditions, as stated in the docs 
<http://guides.rubyonrails.org/active_record_querying.html#hash-conditions>

Only equality, range and subset checking are possible with Hash conditions.


which translates to only using AND, IN and =. Hence, I'm looking for a way 
to enhance the built in support for simple conditions to support something 
similar to what I described above, particularly a way to combine AND and OR 
filtering. 

Sure, I could parse the query parameters and use the different parts to 
build a query using ActiveRecord's other condition methods or by using Arel 
or some of the other tools I mentioned, but that's just it: nothing I've 
come across so far supports this kind of "advanced" filtering by passing 
the filter condition straight from the query parameters to the .where() 
method. It doesn't seem so far fetched since ActiveRecord already offers 
support for simple filtering using hashes and all ORM tools I've looked at 
supports it on a programmatic level. 

So what I'm asking is if anyone knows whether something like this exists, 
or ideas on implementation strategies if I end up doing it myself.



On Monday, March 30, 2015 at 9:57:01 PM UTC+3, Dave Aronson wrote:
>
>
> Other pointers: don't do that.  Don't reinvent SQL and something to 
> implement it as well.  There are reasons not everybody has written a 
> complete database.  Plus, it will be a maintenance *and security* 
> nightmare. 
>
> Look instead at the REST standards.  Yes, there's some ambiguity... 
> but pick what works, for you, *simply*. 
>
> -- 
> Dave Aronson, consulting software developer of Codosaur.us, 
> PullRequestRoulette.com, Blog.Codosaur.us, and Dare2XL.com. 
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/fd17df05-9efd-4826-a947-31da09b17643%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to