我的模型关联如下:
class Group < ActiveRecord::Base
has_many :group_links, :dependent => :destroy
end
class GroupLink < ActiveRecord::Base
belongs_to :group
validates_presence_of :group_id
validates_presence_of :url, :message => "We need a url to create a link"
validates_uniqueness_of :url, :message => "A link with this url already exists"
validates_presence_of :text, :message => "We need a text to create a link"
validates_uniqueness_of :text, :message => "A link with this text already exists"
end
我希望它像在每个组中一样工作,组链接应该是唯一的。然而,它的工作方式是,即使其他一些组具有薄组链接,它也会引发验证错误。
我究竟做错了什么?
提前致谢,