Last active
October 8, 2015 10:02
-
-
Save aquajach/7b43d47df1e60bccf790 to your computer and use it in GitHub Desktop.
Rails STI Pitfall (eager_load off)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person < ActiveRecord::Base | |
| end | |
| class Staff < Person | |
| end | |
| class Teacher < Staff | |
| end | |
| > Person.all.to_sql // "SELECT \"people\".* FROM \"people\"" | |
| > Staff.all.to_sql // "SELECT \"people\".* FROM \"people\" WHERE \"people\".\"type\" IN ('Staff')" WTF! | |
| > Teacher.all.to_sql // "SELECT \"people\".* FROM \"people\" WHERE \"people\".\"type\" IN ('Teacher')" | |
| > Staff.all.to_sql // "SELECT \"people\".* FROM \"people\" WHERE \"people\".\"type\" IN ('Teacher', 'Staff')" Correct now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Teacher.all