mysql - get list of parent records from a list of child records with joins or includes -
lets suppose have models
class parent < activerecord::base has_many :kids end class kid < activerecord::base belongs_to :parent end
and have array of kids
[k1, k2, k3, k4]
i want list of parents of these kids like
[p1, p2]
i want use of includes or joins 1 can me.
if want via active record:
parent.joins(:kids).where("kids.id" => array_of_kids).pluck(:id)
Comments
Post a Comment