I am fairly new to Rails and I was curious as to some of the conventions experts are using when they need to construct a very complex SQL query that contains many conditions. Specifically, keeping the code readable and maintainable.
There are a couple of ways I can think of:
Single line, in the call to find():
@pitchers = Pitcher.find(:all, "<conditions>")
Use a predefined string and pass it in:
@pitchers = Pitcher.find(:all, @conditions)
Use a private member function to return a query
@pitchers = Pitcher.find(:all, conditionfunction)
I sort of lean towards the private member function convention, additionally because you could pass in parameters to customize the query.
Any thoughts on this?