Experiment has_many :features Feature belongs_to :experiment Experiment.where("experiments.id=1") .joins(:features) .pluck("features.id","experiments.id")
我希望这会返回每个功能的ID和实验的ID.
[ [1,1],[2,[3,# .... ]
相反,这将返回实验的ID,然后返回nil
[ [1,nil],[1,# .... ]
这有三个方面很奇怪:
>即使它是一个内连接,只返回一个实验,我能够从功能中提取列(features.name)
>一切都很好,直到重复列名称.
>首先报告最后一个弹出列,就好像第一列被覆盖一样.切换拔除顺序会切换返回值.
这似乎是一个错误,但也许我做错了什么.有小费吗?
SELECT features.id,experiments.id FROM "experiments" INNER JOIN "features" ON "features"."experiment_id" = "experiments"."id" WHERE (experiments.id=1)
注意.这是一个与查询类似的简化问题:
Experiment.where("experiments.id=1") .joins(feature: { child2: { :child3 } }) .pluck("feature.id,child3.id")