【发布时间】:2015-01-09 18:19:53
【问题描述】:
尝试使用 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 不包括更改。只有“添加颜色之前”的创建,更新,“添加颜色之后”的更新。 有人可以告诉我我做错了什么或指出一个例子吗? 我已阅读文档的关联部分,但无济于事。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 associations has-many-through paper-trail-gem