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

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -