如何仅输入唯一关联?
运行以下代码以添加关联每次运行代码时都会输入多个条目:
store.categories << category
有没有办法让它只在db中输入两个模型之间的唯一关联?
直接从导轨指南 ,希望它有所帮助:
class Person has_many :readings has_many :posts, :through => :readings, :uniq => true end
忽略重复项似乎只适用于开始和救援逻辑:
begin stores.categories << category rescue puts "Duplicate entry ignored" end