khiav223577 / deep_pluck

Allow you to pluck attributes from nested associations without loading a bunch of records.
MIT License
460 stars 14 forks source link

Always show the association key even if there is no data #57

Closed khiav223577 closed 1 year ago

khiav223577 commented 1 year ago

Something if we deep_pluck a model with assocation, Ex:

User.deep_pluck(:name, 'city' => :name)

The result hash may not contain 'city' key in that the user doesn't have a city. Ex:

{ 'name' => 'Pearl' }

We want the result always contain the key, Ex:

{ 'name' => 'Pearl', 'city' => nil }