Closed TaylorMerritt closed 3 years ago
I am able to work around this setting up the has_and_belongs_to_many
manually:
class County < ApplicationRecord
has_many :counties_zipcodes
has_many :zipcodes, through: :counties_zipcodes
end
class Zipcode < ApplicationRecord
has_many :counties_zipcodes
has_many :counties, through: :counties_zipcodes
end
class CountiesZipcode < ApplicationRecord
belongs_to :county
belongs_to :zipcode
end
[19] pry(main)> County.limit(2).deep_pluck(zipcodes: :city)
(0.4ms) SELECT counties.id FROM "counties" LIMIT 2
(4.6ms) SELECT counties_zipcodes.county_id, "zipcodes"."city" FROM "zipcodes" INNER JOIN "counties_zipcodes" ON "counties_zipcodes"."zipcode_id" = "zipcodes"."id" WHERE "counties_zipcodes"."county_id" IN (178, 179)
[
[0] {
:zipcodes => [
[ 0] {
"city" => "Alpine"
},
...
Thanks for your report. I'm going to take a look at it.
Thank you!
Hi, @taylor-au
I just released deep_pluck
v1.1.8
The issue should be fixed in this version. 😃
For more details, see the changelog.
It is working correctly for me. Thank you very much @khiav223577 !
I'm not sure if it's possible to do so, but I'm having an issue using
deep_pluck
with ahas_and_belongs_to_many
association.Example data structure:
When I try to use
deep_pluck
on this association I get the following:So it appears to be using the correct joins table for the
SELECT
andWHERE
, but not theFROM
.