Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 532
Paul A Jungwirth Avatar asked Jan 23 '26 03:01

Paul A Jungwirth


1 Answers

User.first.jobs.scoped.to_sql

like image 130
DGM Avatar answered Jan 24 '26 21:01

DGM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!