sql - Finding all users with specific attribute in a through relation -


See below for details.

I am trying to write a line of code, search the database and show users who have specific skills.

My clue is that I should use something like @ user.where ('skill =?', skillvariable). > Or a specific query

Description :

I have a user model, a skill model and a user_skill model.

I have the relation in user.rb_m: skill, through: user_skills .

I have a relationship with skill.rb Has_many: user_skills and has_many: users, through :: user_skills ,

and Then, in user_skills.rb, I have related_to: user and related_to: skills .

/ P>

  t.string "name" t.string "slug"    

You can do just that:

  User.includes (skills:). This will be lateral:  

All users with at least one skill named 'Archery' will be there (skill: {name: 'arrowy'})

Recover.


Same question:



Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -