I'm a React, Javascript & Rails full-stack Software Engineer. I have been working remotely for the past two years in a remote village. Before joining as a Software Engineer I founded kwiq - a hyperlocal delivery startup to deliver things in remote villages.
1 minute read
Ruby 3.1 introduced the Array#intersect? method which returns true if two arrays have at least one common element, otherwise returns false.
Before
To check if two ActiveRecord relation objects have any common elements, we had to chain the intersection method with any? or empty? methods.
But the ActiveRecord::Relation did not have built-in support for the Array#intersect method.
After
Rails 7.1 added the Array#intersect? method to ActiveRecord::Relation.
With this intersect? method, we can check if two ActiveRecord relation objects have any common elements or not.