Paul A Jungwirth
Paul A Jungwirth

Reputation: 24551

Get the SQL for a Rails 3 Association

I really like how in Rails 3 you can ask a scope for its SQL like this:

User.admins.to_sql

Is there any way to do the same thing with a has_many relation?:

User.first.jobs.to_sql

I've tried User.first.jobs.public_methods.grep /sql/ and other tricks, but I haven't turned up anything.

Upvotes: 3

Views: 484

Answers (1)

DGM
DGM

Reputation: 26979

User.first.jobs.scoped.to_sql

Upvotes: 4

Related Questions