News for hackers. Stuff that matters.

aurisor

Re:The Troublesome Active Record Pattern on Thursday March 19, 2020 @11:22AM (#22628314)
> ISBNs of all deceased Italian authors

  Book.joins(:author).where(author: { deceased: true }).map &:isbn`
> first class transactions / decrement race condition

  Book.find(isbn: 1).decrement :copies_in_stock
> Row-locking

  Book.transaction do
    b = Book.lock("FOR UPDATE NOWAIT").find_(1)
    # logic around handling out of stock
    b.copies_in_stock -= 1
    b.save!
  end
Those are all of your examples and the Ruby code that implements the solution you want. (Disclaimer: there are probably small syntax errors here, you get the gist)

Honestly this article sounds like it was written by someone who read a 10 year old Martin Fowler article and decided to critique it without even a cursory understanding of modern ORMs. Even more strangely, when everyone starts pointing out the obvious fact that ORMs do solve these problems in practice, you've decided to move the goalposts to say "oh, well the straw man abstract pattern doesn't solve for these real-world problems."

In the future I'd recommend you familiarize yourself with a problem space before trying to publish on it.

Re:The Troublesome Active Record Pattern on Thursday March 19, 2020 @10:05AM (#22627580)
It is a major problem in practice. It's called the "N+1" problem and it's exhaustively studied and documented, with mitigation strategies for every ORM that encounters it.

This is a bit like acting as if you're the first person to realize that null pointer deferences are a problem and happily telling the entire world to "just switch to pass by value."