Rails 6.1 adds ActiveRecord::FinderMethods 'sole' and 'find_sole_by' | BigBinary Blog
04-Mar-2021 1421
There were no methods defined to find and assert the presence of exactly one record at the same time.For example, we have a class Product with a price field and we want to find a single product that has a price of 100. For zero or multiple products with the price of 100, we want to raise an error. We can not add database constraints to make a unique field of price.Now to solve the above query, we don't have any method defined in ActiveRecord::FinderMethods module. We can find a product with the given price or raise an error if no record is found using the queries mentioned in the below example.
Rails 6.1 adds ActiveRecord::FinderMethods 'sole' and 'find_sole_by' | BigBinary Blog #ruby #rubydeveloper #rubyonrails #Rails #ActiveRecord::FinderMethods #'sole' #'find_sole_by' #BigBinary #activerecord::findermethods #bigbinary #blog https://rubyonrails.ba/link/rails-6-1-adds-activerecord-findermethods-sole-and-find_sole_by-bigbinary-blog