4 ms·
I keep telling people to accomplish this by encapsulating the query in a DB view, and using a read only active record model in front of it. You can then query t
by ikawe 10y ago
I keep telling people to accomplish this by encapsulating the query in a DB view, and using a read only active record model in front of it. You can then query the table through the AR interface, and use has_many and friends. Unlike using execute_sql where everything is a string, type coercion works as you'd expect.
This solves the problem if you know ahead of time the format of the query, e.g. The example you gave would probably fit well. But if you're offering some kind of query building interface, well god help you.
No one has told me I'm wrong yet with this approach and it's been working great for years.
- sanderjd 10y agoYeah, views are a good approach. Adding more first-class support for them would be a valuable improvement.