Skip to content

Instantly share code, notes, and snippets.

@aquajach
Last active October 8, 2015 10:02
Show Gist options
  • Select an option

  • Save aquajach/7b43d47df1e60bccf790 to your computer and use it in GitHub Desktop.

Select an option

Save aquajach/7b43d47df1e60bccf790 to your computer and use it in GitHub Desktop.
Rails STI Pitfall (eager_load off)
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
@ghprince
Copy link

ghprince commented Oct 8, 2015

Teacher.all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment