You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[2] pry(main)> Student.as_of(Time.now).includes(:school, :city, :country).map(&:country).all?
Student Load (1.7ms) SELECT "students".* FROM (SELECT "history"."students".* FROM "history"."students" WHERE ( '2022-05-19 11:14:38.961991'::timestamp <@ history.students.validity )) "students"
School Load (0.4ms) SELECT "schools".* FROM (SELECT "history"."schools".* FROM "history"."schools" WHERE ( '2022-05-19 11:14:38.961991'::timestamp <@ history.schools.validity )) "schools" WHERE "schools"."id" IN ($1, $2) [["id", 1], ["id", 2]]
City Load (0.3ms) SELECT "cities".* FROM (SELECT "history"."cities".* FROM "history"."cities" WHERE ( '2022-05-19 11:14:38.961991'::timestamp <@ history.cities.validity )) "cities" WHERE "cities"."id" IN ($1, $2) [["id", 1], ["id", 2]]
Country Load (0.2ms) SELECT "countries".* FROM (SELECT "history"."countries".* FROM "history"."countries" WHERE ( '2022-05-19 11:14:38.961991'::timestamp <@ history.countries.validity )) "countries" WHERE "countries"."id" IN ($1, $2) [["id", 1], ["id", 2]]
=> true
Rails 7
3.1.2 :004 > Student.as_of(Time.now).includes(:school, :city, :country).map(&:country).all?
Student Load (1.3ms) SELECT "students".* FROM (SELECT "history"."students".* FROM "history"."students" WHERE ( '2022-05-19 11:14:09.421689'::timestamp <@ history.students.validity )) "students"
School Load (0.5ms) SELECT "schools".* FROM (SELECT "history"."schools".* FROM "history"."schools" WHERE ( '2022-05-19 11:14:09.421689'::timestamp <@ history.schools.validity )) "schools" WHERE "schools"."id" IN ($1, $2) [["id", 1], ["id", 2]]
City Load (0.6ms) SELECT "cities".* FROM (SELECT "history"."cities".* FROM "history"."cities" WHERE ( '2022-05-19 11:14:09.421689'::timestamp <@ history.cities.validity )) "cities" WHERE "cities"."id" IN ($1, $2) [["id", 1], ["id", 2]]
City Load (0.2ms) SELECT "cities".* FROM "cities" WHERE "cities"."id" IN ($1, $2) [["id", 1], ["id", 2]]
Country Load (0.2ms) SELECT "countries".* FROM (SELECT "history"."countries".* FROM "history"."countries" WHERE ( '2022-05-19 11:14:09.421689'::timestamp <@ history.countries.validity )) "countries" WHERE "countries"."id" IN ($1, $2) [["id", 1], ["id", 2]]
=> false
Preload is broken on Rails 7 with through-through associations
Rails 6
Rails 7
Rails 6: diowa/ruby3-rails6-bootstrap-heroku@d748a7e
Rails 7: diowa/ruby3-rails7-bootstrap-heroku@88842de
As we can see, Rails 7 performs an extra load outside of the history on the table in the middle
The text was updated successfully, but these errors were encountered: