Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with through associations #163

Closed
2 tasks done
tagliala opened this issue May 19, 2022 · 0 comments · Fixed by #164
Closed
2 tasks done

Issue with through associations #163

tagliala opened this issue May 19, 2022 · 0 comments · Fixed by #164
Labels

Comments

@tagliala
Copy link
Member

tagliala commented May 19, 2022

  • describe problem
  • add failing spec

Models

class Country < ApplicationRecord
  include ChronoModel::TimeMachine

  has_many :cities, dependent: :destroy
  has_many :schools, through: :cities
end

class City < ApplicationRecord
  include ChronoModel::TimeMachine

  validates :name, presence: true

  belongs_to :country
end

class School < ApplicationRecord
  include ChronoModel::TimeMachine

  belongs_to :city
  has_one :country, through: :city
end

Test

Country.destroy_all
italy = Country.create!(name: 'Italy')
rome = italy.cities.create!(name: 'Rome')
galilei = rome.schools.create!(name: 'G. Galilei')
ts = Time.now
sleep 1
buonarroti = rome.schools.create!(name: 'M. Buonarroti')

Country.as_of(ts).includes(:schools).first.cities.last.schools.map(&:name).sort == [galilei.name]

Expected Result

["G. Galilei"]

Actual Result

["G. Galilei", "M. Buonarroti"] 
tagliala added a commit that referenced this issue May 19, 2022
tagliala added a commit that referenced this issue May 20, 2022
tagliala added a commit that referenced this issue May 20, 2022
@tagliala tagliala added the bug label May 20, 2022
tagliala added a commit that referenced this issue May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant