search for: validates_uniqueness

Displaying 13 results from an estimated 13 matches for "validates_uniqueness".

2006 Nov 29
2
validates_uniqueness w scope
In a one-to-many relationship (domain has_many :categories and category belongs_to :domain) In the category model I use: validates_uniqueness_of :name, :case_sensitive => false but upon creation of a category this validation is performed on ALL domains, can I restrict it only to the categories of the current domain, the to which teh category being saved belongs_to ? if yes ? how ? thanks for your help -- Posted via http://www.rub...
2006 Apr 27
0
DRY validation
...llows you to do this. Here''s an example from one of my models: class Country < ActiveRecord::Base attribute :name, :string do |a| a.validates_length :within => 1..48 a.validates_format :with => /\A[A-Z](?:\s*[''\(-]?[A-Za-z]+[,\. \)]?)*\z/ a.validates_uniqueness end attribute :code_alpha2, :string do |a| a.validates_length :is => 2 a.validates_format :with => /\A[A-Z]+\z/ a.validates_uniqueness end attribute :code_alpha3, :string do |a| a.validates_length :is => 3 a.validates_format :with =&...
2005 Jul 26
3
Generating unique random tokens for ActiveRecord objects
...save the new row. What I''d like to do is declare a unique index in the database, have my model object catch a failed save, check if it failed due to the token not being unique, regenerate the token, and retry the save. Is there any neat way to do this in ActiveRecord? (How does validates_uniqueness do it? Does it suffer from the same timing problem?) Cheers, Pete Yandell _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
2009 Jul 04
12
save! not allowed after validates_uniqueness
I have this in a model validates_uniqueness_of :aspect, :scope => :user_id In an instance method of the same model I have "save!" but I don''t touch the :aspect attribute in that instance method at all. Whenever that save! command is run however I get this error: ActiveRecord::RecordInvalid: Validation failed:...
2007 Jan 01
5
Validations based on associations
My model is very simple, it''s mostly just a join table that represents which tournaments a user has registered for. class Registration < ActiveRecord::Base belongs_to :user belongs_to :tournament validates_presence_of :user_id, :tournament_id validates_uniqueness_of :user_id, :scope => :tournament_id end the validates_uniqueness checks to make sure there''s no record that has the same user_id and tournament_id. Is there a relatively easy way to specify this behavior? The only way that I know is to do something like context "A Registratio...
2007 Aug 23
6
controller spec with model that validates_uniqueness
...ec: Image.stub!(:find).and_return(@image) @image.should_receive(:save!).once.with(:any_args) put :update, :id => @image.id, :category_id => @category.id, :image => {:name => ''test'', :image_number => 13554} #model validates_presence_of :name validates_uniqueness_of :name, :allow_nil => true # rspec output ActiveRecord::RecordInvalid in ''ImagesController should update a database record when it receives a PUT'' Validation failed: Name has already been taken, Image number has already been taken It seems AR is not detecting that thi...
2006 May 23
11
putting the schema in the model files
THE SCHEMA IN THE MODEL a small write up on ''putting the schema in the model'' This is a write up on an issue best covered in a mailing list thread of Januari 2006 (see the links in the text), I repost it because I think it deserves a place on the agenda. == Why? == I was switching back and forward between the model files and the schema.rb -- off course I have
2006 Jun 07
3
validates_uniqueness_of two fields
Is it possible to do a validates_uniqueness_of :name, :zip but only in that context? I''d like to be able to have that zip used again, but not in conjunction with a name already with that zip. Does that make sense? -- Posted via http://www.ruby-forum.com/.
2006 Apr 22
0
Remove validation for a property
Hi Does anyone here know a way who I could remove the validation for a model''s property? For example, I would like to have in one file: class A < ActiveRecord::Base validates_uniqueness :title end And in another file I want to override or rather remove the validation: class A < ActiveRecord::Base # somehow stop validating :title for uniqueness end The purpose of this? Well, I could provide a model "A" in a plugin or component and change its behaviou...
2006 Jan 15
0
How to Validate Inherintly?
Very often, I''d like to know if an object is .valid? inherently - that is, if it meets all the validations that are run on it by itself, but I don''t care if one of the fields is not unique. What''s the best way to determine this - that is, to run all the validations except the validates_uniquness ones? (A common use case is when importing data - it''s
2008 Mar 14
5
Branching scenarios, GivenScenario and database
I''m trying to use stories to drive some high-level design. I''ve got some branching scenarios where I want to follow a scenario, to establish a base situation, and then have different scenarios which ''branch'' out from that state, possibly several levels deep. I asked a bit about this a few days ago, and David pointed out the rather undocumented GivenScenario
2010 Jun 15
8
Allow blank on should validate_uniqueness_of
Hello, Using shoulda, any ideas how to allow blank when having this test: should validate_uniqueness_of(:email) Thanks. -- J. Pablo Fernández <pupeno-GAtDADarczzQT0dZR+AlfA@public.gmane.org> (http://pupeno.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
2009 Sep 25
12
uniqueness validation perplexity
I want to write a validate routine to check to enforce that a position must be unique in a category. (In another category, it doesn''t have to and shouldn''t need to be unique.) I write this code which works happily for new items: def position_in_category_not_unique @items = Item.find( :all, :conditions => [ "category_id = ? AND position = ?", category_id,