4 ms·
> ISBNs of all deceased Italian authors Book.joins(:author).where(author: { deceased: true }).map &:isbn` > first class transactions / decrement race condit
by aurisor 7y ago
> 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.