[[+content_image]]
M
M
Meridian3122014-04-24 18:33:20
Ruby on Rails
Meridian312, 2014-04-24 18:33:20

How to modify SQL query using Rails relationships?

This is automatically generated
SELECT "users".* FROM "users" INNER JOIN "workspace_roots" ON "users"."id" = "workspace_roots"."user_id" WHERE "workspace_roots"."root_id" = ? [["root_id", 2]]
It is necessary to put another value instead of 2, despite the fact that this value is taken from another object accessible by reference.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
K
Kirill Platonov, 2014-04-24
@kirillplatonov

User.joins(:workspace_roots).where(workspace_roots: { root_id: 5 })

5 replace with the desired ID

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question