mardi 4 août 2015

Ruby on Rails join, where without losing associated objects

i am using ruby 2.1.5 on rails 4.2 and got a little problem I got Users and with a has many relation logins.

@users = User.joins(:logins).where("country LIKE ?", "%#{params[:searchc]}%").uniq

I want to find Users depending on the logins but i cant figure out a good solution to show the associated objects in my view too. With the join i lose the associated logins and only the found ones are left but i need all. Start a new load login ( @users.first.logins) in the view for each user is very slow...

Aucun commentaire:

Enregistrer un commentaire