现在的思路是,用户每点击一下属性下的属性值,就会向后台发送一次请求,然后根据返回的数据更新这几个。 每次发送数据,会把已经点击了的作为一个数据,还未点击的作为一个数据,发送到后台。然后根据这两个数据搜索数据库, 得出未选择的属性里,哪些属性值是要禁选的。 但是怎样搜索数据库,我想了很久,试了很多,还不能成功,请教下各位! 数据表设计我是参考 spree 的,如下:
#分类
class Taxon < ActiveRecord::Base
has_many :products, dependent: :destroy
has_many :option_types, dependent: :destroy
end
#商品
class Product < ActiveRecord::Base
belongs_to :taxon
has_many :product_option_types, dependent: :destroy, inverse_of: :product
has_many :option_types, through: :product_option_types
has_many :variants, dependent: :destroy
end
#变体
class Variant < ActiveRecord::Base
belongs_to :product
has_many :order_products
has_many :option_value_variants, dependent: :destroy, inverse_of: :option_value
has_many :option_values, through: :option_value_variants
end
#属性
class OptionType < ActiveRecord::Base
has_many :option_values, dependent: :destroy\
has_many :product_option_types, dependent: :destroy, inverse_of: :option_type
has_many :products, through: :product_option_types
end
#属性值
class OptionValue < ActiveRecord::Base
belongs_to :option_type
has_many :option_value_variants, dependent: :destroy, inverse_of: :variant
has_many :variants, through: :option_value_variants
end