Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 附加后未运行的保存回调_Ruby_Datamapper - Fatal编程技术网

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