Tim Conner wrote:> Consider the following table:
> +----+--------+--------+-----------+
> | id | seq_no | request| response |
> +----+--------+--------+-----------+
> | 42 | 1 | req1 | 0106 |
> | 43 | 2 | req2 | 2343 |
> | 44 | 3 | test | OK |
> +----+--------+--------+-----------+
>
> I in the model that wraps this table, i have defined a constraint that
> validates the uniqueness of the response for each request type. I.e.
> validates_uniqueness_of :response, :scope => :request, :if =>
:response?
>
> However, I not want to modify this constraint so that the uniqueness is
> only validated for requests re1 and req2. i.e. I want to be able to
> create the following table.
> +----+--------+--------+-----------+
> | id | seq_no | request| response |
> +----+--------+--------+-----------+
> | 42 | 1 | req1 | 0106 |
> | 43 | 2 | req2 | 2343 |
> | 44 | 3 | test | OK |
> | 45 | 4 | test | OK |
> +----+--------+--------+-----------+
>
> What should my validates_uniqueness_of statement look like?
Hi Tim,
May be this will help
validates_uniqueness_of :response, :scope => :request, :if =>
ModelName.new{|model_names| model_names.request != "test" }
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---