Before Rails 6,
if we want to extract associated records from an
we would use
we want to fetch
subscriptions of some
The query would look as shown below.
1User.where(blocked: false).preload(:subscriptions).collect(&:subscriptions) 2 3=> # returns collection of subscription records
ActiveRecord::Relation#extract_associated provides a shorthand to achieve same result and is more readable than former.
1User.where(blocked: false).extract_associated(:subscriptions) 2 3=> # returns the same collection of subscription records
Here's the relevant pull request for this change.