【发布时间】:2012-03-29 19:50:40
【问题描述】:
我有三个模型。销售、物品和图像。我想验证在创建销售时,每次销售至少有三张照片和一件或多件商品。实现这一目标的最佳方法是什么?
销售模式:
class Sale < ActiveRecord::Base
has_many :items, :dependent => :destroy
has_many :images, :through => :items
accepts_nested_attributes_for :items, :reject_if => lambda { |a| a[:title].blank? }, :allow_destroy => true
end
物品型号:
class Item < ActiveRecord::Base
belongs_to :sale, :dependent => :destroy
has_many :images, :dependent => :destroy
accepts_nested_attributes_for :images
end
图像模型:
class Image < ActiveRecord::Base
belongs_to :item, :dependent => :destroy
end
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 activerecord activemodel