0

尝试使用 PaperTrail 进行版本控制我的关联没有恢复。我一定做错了什么。这是与我的类似设置。我正在使用 PaperTrail 的最新主分支。

class Ball < ActiveRecord::Base
  has_many :ball_colors
  has_many :colors, through: :ball_colors
  has_paper_trail
end

class BallColor < ActiveRecord::Base
  belongs_to :ball 
  belongs_to :color
  has_paper_trail
end

class Color < ActiveRecord::Base
  has_paper_trail
  has_many :ball_colors
  has_many :balls, through: :ball_colors
end

这就是我正在做的事情。

ball = Ball.create()
ball.name = 'Before I add color'
ball.save

ball.colors << Color.create(name: 'blue')
ball.save #although this is unnecessary i think 

ball.name = 'After adding color'
ball.save

b = ball.versions.last.reify(:has_many => true)
b.save

b.reload
b.name  #=> 'Before I add color'
b.colors #=> [Blue] 

b.colors 应该是空的。此外,当我向球添加颜色时,ball.versions 不包括更改。只有“添加颜色之前”的创建,更新,“添加颜色之后”的更新。有人可以告诉我我做错了什么或指出一个例子吗?我已阅读文档的关联部分,但无济于事。

4

2 回答 2

0

如果我正确理解文档,则意味着纸质记录能够恢复关联。

请参阅项目github页面关联章节。

于 2015-03-30T14:30:32.833 回答
0

应该是ball.versions.last.reify(:has_many => true).save!reify只是向您展示我认为的以前的版本。

于 2015-07-23T16:43:51.133 回答