Ruby 附加后未运行的保存回调
我在尝试使用Ruby 附加后未运行的保存回调,ruby,datamapper,Ruby,Datamapper,我在尝试使用添加关系时遇到问题,您缺少关系,has n,:cuts class Color include DataMapper::Resource property :id, Serial property :name, String has n, :cuts has n, :fabrics, :through => Resource end 想详细说明一下吗?你是说模型不见了?(事实并非如此;我在帖子中将其排除在外)或者我需要在我的颜色
添加关系时遇到问题,您缺少关系,has n,:cuts
class Color
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :cuts
has n, :fabrics, :through => Resource
end
想详细说明一下吗?你是说模型不见了?(事实并非如此;我在帖子中将其排除在外)或者我需要在我的颜色中添加一个或多个剪切以使其正确工作?为什么会产生这种行为?
class Color
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :cut
has n, :fabrics, :through => Resource
end
yellow = Color.new(:name => "yellow")
red = Color.new(:name => "red")
f = Fabric.create(:name => "tricot", :fixed_color => false)
f.colors << red
f.save
f.colors << yellow
f.save
puts f.colors.size
=> 0
=> 2
f.colors = f.colors + [red]
f.save
f.colors = f.colors + [yellow]
f.save
puts f.colors.size
=> 0
=> 1
=> 2
=> 2
class Color
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :cuts
has n, :fabrics, :through => Resource
end