Experiment has_many :features Feature belongs_to :experiment Experiment.where("experiments.id=1") .joins(:features) .pluck("features.id", "experiments.id")
I expect this to return the identifier of each function and the experiment identifier.
[ [1, 1], [2, 1], [3, 1], # .... ]
Instead, the experiment id is returned, and then nil
[ [1, nil], [1, nil], [1, nil], # .... ]
This is strange in three ways:
- although this is an inner join, only the Experiment returns. I can cut columns from functions (features.name).
- everything is fine until the column name is repeated.
- first the last plucked column is displayed, as if the first column was overwritten. Toggle pop order returns the return value.
This seems like a mistake, but maybe I'm doing something wrong. Any tips?
SQL output:
SELECT features.id, experiments.id FROM "experiments" INNER JOIN "features" ON "features"."experiment_id" = "experiments"."id" WHERE (experiments.id=1)
Note. This is a simplified question related to a query similar to:
Experiment.where("experiments.id=1") .joins(feature: { child2: { :child3 } }) .pluck("feature.id, child3.id")
ruby sql ruby-on-rails
nate
source share