|
|
|
|
|
by Dangeranger
2583 days ago
|
|
Long ago I liked ActiveRecord(AR), then I worked at a company that did large aggregations in SQL and found it to be severely limited in working with complex queries which use many JOIN statement and sub-queries. During that time I came to enjoy working with the Sequel[0] gem, and its fantastic documentation. Now, after working with Ecto[1] in Elixir, I've found that the ROM[2] builder pattern is a better approach to abstracting SQL and mapping the results to Ruby objects. It's much cleaner and more maintainable than a long mess of AR queries. Ryan Bigg wrote a great book about breaking away from AR in Rails called Exploding Rails[3]. It's a good read. [0] http://sequel.jeremyevans.net/ [1] https://github.com/elixir-ecto/ecto [2] https://rom-rb.org/5.0/learn/introduction/active-record/ [3] https://leanpub.com/explodingrails |
|
I would certainly agree that SQL > AR once your queries grow past a certain (fairly low) complexity threshold.
But, AR (wisely) doesn't try to be a complete replacement for SQL. It very happily (and even elegantly, I might say?) lets you use raw SQL pretty much any time you, the developer, feel it's more convenient/productive. That principle is pretty explicitly baked into AR.
Many ORM frameworks don't make this easy at all, whereas with AR it's very painless.
I have a lot of beef with AR but I think this is one of its strong points.