class Foo < ActiveRecoed::Base
has_many :www_links, :as => :owner
end
class WwwLink < ActiveRecord::Base
belongs_to :owner, :polymorphic => true
attr_accessible :href
end
I want to ensure that each Foo instance does not have same links (href).
My first attempt would be to write validation in Foo that checks all its
www_links. But then I would also have to do it in WwwLink class. That
would not be DRY.
So you are just wanting uniqueness of www_link.href? Will not
validates_uniqueness_of in WwwLink class (backed up by a unique
constraint in the database of course) do the job? I think in this
case it will be the foo2.www_links.create that will fail.
So you are just wanting uniqueness of www_link.href? Will not
validates_uniqueness_of in WwwLink class (backed up by a unique
constraint in the database of course) do the job? I think in this
case it will be the foo2.www_links.create that will fail.
Colin
The constraint is on “owner” and “href”, not “href” itself.
I can have multiple links with the same href. But those cannot be with
the same owner_id.
So you are just wanting uniqueness of www_link.href? Will not
validates_uniqueness_of in WwwLink class (backed up by a unique
constraint in the database of course) do the job? I think in this
case it will be the foo2.www_links.create that will fail.
Colin
The constraint is on “owner” and “href”, not “href” itself.
I can have multiple links with the same href. But those cannot be with
the same owner_id.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.