Skip to content

through association is not supported #390

@tamaskamaras

Description

@tamaskamaras

Description

Time-travel uses the present object of the through association.

ref: #295

Models

class ActivityStep < ApplicationRecord
  include ChronoModel::TimeMachine

  belongs_to :activity_roadmap
end

class ActivityRoadmap < ApplicationRecord
  include ChronoModel::TimeMachine

  has_many :activity_steps, dependent: :destroy, inverse_of: :activity_roadmap
  belongs_to :activity_lot, optional: true
end

class ActivityLot < ApplicationRecord
  include ChronoModel::TimeMachine

  has_one :activity_roadmap, dependent: :destroy
  has_many :activity_steps, through: :activity_roadmap
end

Seeds

activity_lot = ActivityLot.create!
activity_roadmap1 = ActivityRoadmap.create!(activity_lot: activity_lot)
activity_step1 = ActivityStep.create!(activity_roadmap: activity_roadmap1)

Output in the present

CORRECT ✔️

activity_lot.activity_steps.ids
=> [111]

Creating a new :through Object

activity_roadmap1.destroy!
activity_roadmap2 = ActivityRoadmap.create!(activity_lot: activity_lot)
activity_step2 = ActivityStep.create!(activity_roadmap: activity_roadmap2)

Output in the present

CORRECT ✔️

activity_lot.activity_steps.ids
=> [222]

Output in history

WRONG ❌

activity_lot.as_of(1.second.ago).activity_steps.ids
=> []

Expected: [111] (the historical ids)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions