Re:The Troublesome Active Record Pattern
by ptr on Thursday March 19, 2020 @03:27AM
(#22625333)
An article dedicated to why Rail's Active Record library isn't actually using the Active Record pattern would be interesting!
[ Parent
| on HN ]
Rails' ActiveRecord is both a query builder and also the canonical Active Record pattern. For example, one can say
book = Books.joins(:authors).where(author_name: 'James S. A. Corey').first
book.title = "Tiamat's Wrath"
book.save!
It's not that they stopped supporting the Active Record pattern, it's that they rebuilt the whole thing a few years ago with a real relational query builder under the hood.Not to detract from your point, but rails 3 was released with arel in 2010, so it has used a relational query builder for a decade at this point.
Thanks, I wasn't super clear on the timeline there.
Re:The Troublesome Active Record Pattern
by inopinatus on Thursday March 19, 2020 @07:50AM
(#22626584)
Itβs more like the repository pattern under the bonnet.
Re:The Troublesome Active Record Pattern
by calpaterson on Thursday March 19, 2020 @04:01AM
(#22625480)
Yes I am curious about that. Someone else said that the Rails authors used to like and defend this pattern and that presumably they changed their mind. Maybe because they ran into problems? I'm not at all close to the Ruby community but would love to know.
https://lobste.rs/s/valayp/troublesome_active_record_pattern...
That's my general impression. As Rails grew in popularity and was used for more and more complex things (with more and more complex database tables), they started to add in the raw query building parts of ActiveRecord. Though I think it was more that they wanted raw query functionality in the library and it made most sense to enhance the tool that already dealt with the database rather than add another alongside it.