Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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 on rails 如何使多态连接成为依赖关系?_Ruby On Rails_Ruby On Rails 3_Polymorphic Associations_Polymorphism - Fatal编程技术网

Ruby on rails 如何使多态连接成为依赖关系?

Ruby on rails 如何使多态连接成为依赖关系?,ruby-on-rails,ruby-on-rails-3,polymorphic-associations,polymorphism,Ruby On Rails,Ruby On Rails 3,Polymorphic Associations,Polymorphism,当产品或图像被删除时,我试图使我的图像映射被销毁。这是代码 class ImageMap < ActiveRecord::Base belongs_to :imageable, :polymorphic => true belongs_to :image end class Product < ActiveRecord::Base has_many :image_maps, :as => :imageable has_many :images, :thr

当产品或图像被删除时,我试图使我的图像映射被销毁。这是代码

class ImageMap < ActiveRecord::Base
  belongs_to :imageable, :polymorphic => true
  belongs_to :image
end

class Product < ActiveRecord::Base
  has_many :image_maps, :as => :imageable
  has_many :images, :through => :image_maps
end

class Image < ActiveRecord::Base
  has_many :image_maps, :as => :imageable, :dependent => :destroy
end
class ImageMaptrue
属于:图像
结束
类产品:imageable
有很多:图像,:至=>:图像
结束
类映像:imageable,:dependent=>:destroy
结束

现在,当您删除图像时,图像映射不会被破坏,我仍然需要弄清楚如何使其也适用于产品。

我认为您的家属应该使用图像映射模型


如果我没记错的话,这就是Rails检查关联模型以确定它们是否需要销毁的内容。

我尝试过,但当我尝试将图像与产品关联时,它删除了产品lol.hmm,因为关联,我想您需要回调。也许这有助于: