Hacker News new | ask | show | jobs
by house9-2 1628 days ago
Rails 7 has finally added this to active record: sole and find_sole_by

Both raise an exception unless a single record is found.

Of course this would not make a difference when working with mongoid... I also like the fail fast approach.

https://blog.saeloun.com/2021/03/16/rails-adds-sole-and-find...

1 comments

Finally! I don't like the name though. but I'll live with it. Well, at least they added it to Enumerable, so you could use it with mongoid.