Iain Rose
2006-Feb-11 07:03 UTC
[Rails] validates_uniqueness_of - how to use multiple values for scope
Hi I''m trying to create a basic test management tool to organise the manual testing I have to do. I''m working on the results recording module and have a problem. Basically, I want each test result to belong to a test case, a test environment and a build. I want to make sure there''s no duplication of results with these 3 properties. If someone tries to enter a new test result for a test thats already been run on a certain environment with a certain build I want the user to be prompted to update the existing result rather than create a new one. In the result model, I know I can use .... validate_uniqueness_of :test_id, :scope => "xxxxx" .... but I need it to be unique for 2 fields (environment and build) Is there any way to pass 2 values into the scope attribute? If not can anyone suggest how to update the validate_uniqueness_of method to do this? thanks Iain -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060211/b343bfeb/attachment.html
Kent Sibilev
2006-Feb-11 07:33 UTC
[Rails] validates_uniqueness_of - how to use multiple values for scope
You can do this only using edge(svn) version of Rails. You should pass an array of scope fields. Kent On 2/11/06, Iain Rose <iain.rose@gmail.com> wrote:> Hi > > I''m trying to create a basic test management tool to organise the manual > testing I have to do. I''m working on the results recording module and have a > problem. > > Basically, I want each test result to belong to a test case, a test > environment and a build. > > I want to make sure there''s no duplication of results with these 3 > properties. If someone tries to enter a new test result for a test thats > already been run on a certain environment with a certain build I want the > user to be prompted to update the existing result rather than create a new > one. > > In the result model, I know I can use .... > > validate_uniqueness_of :test_id, :scope => "xxxxx" > > .... but I need it to be unique for 2 fields (environment and build) > > Is there any way to pass 2 values into the scope attribute? > > If not can anyone suggest how to update the validate_uniqueness_of method to > do this? > > thanks > > Iain > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Jeff McDonald
2006-Feb-11 07:44 UTC
[Rails] validates_uniqueness_of - how to use multiple values for scope
I heard of an upcoming change to validates_uniqueness_of that will allow for multiple validation, but until then, this should work: --------------------- # Make sure each (id, environment, build) tuple is unique for model TestCase validates_each :test_id, :on => :create do |record, test, value| if TestCase.find_by_id_and_environment_and_build(record.attributes[''id''], record.attributes[''environment''], record.attributes[''build'']) record.errors.add test, "This (id,environment,build) tuble has already been added" end end --------------------- -- Jeff On 2/10/06, Iain Rose <iain.rose@gmail.com> wrote:> Hi > > I''m trying to create a basic test management tool to organise the manual testing I have to do. I''m working on the results recording module and have a problem. > > Basically, I want each test result to belong to a test case, a test environment and a build. > > I want to make sure there''s no duplication of results with these 3 properties. If someone tries to enter a new test result for a test thats already been run on a certain environment with a certain build I want the user to be prompted to update the existing result rather than create a new one. > > In the result model, I know I can use .... > > validate_uniqueness_of :test_id, :scope => "xxxxx" > > .... but I need it to be unique for 2 fields (environment and build) > > Is there any way to pass 2 values into the scope attribute? > > If not can anyone suggest how to update the validate_uniqueness_of method to do this? > > thanks > > Iain > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >