Displaying 20 results from an estimated 80000 matches similar to: "validates_uniqueness_of with conditions"
2007 Jul 30
3
validates_uniqueness_of doesn't work if value tested is numeric and column is string
Hello all,
I am working through the depot example in the rails book.  If I add a
validates_uniqueness_of to a string column in the model, and then try
to create a record with a number in this string column I get an SQL
error.  Looks like the SQL generated to test for uniqueness does not
quote the value if it''s numeric even though it''s comparing against a
varchar column.  It does
2007 May 28
2
out-cheat validates_uniqueness_of
before_save :strip_strings
     validates_uniqueness_of :username
     validates_presence_of :username
      	
     private
   	
     def strip_strings
         self.username = username.gsub!(" ","")
     end
example:
username = "    gissmoh-/upiLifMog2ELgA04lAiVw@public.gmane.org   "
becomes gissmoh-/upiLifMog2ELgA04lAiVw@public.gmane.org
and is stored in the
2008 Jan 26
1
validates_uniqueness_of customization
Hey,
I have a simple web app where I would like users to sign up with a
maximum of two accounts per email address. What would be the rails way
of accomplishing this. Is there anyway of modifying
validates_uniqueness_of to perform the proper validations?
Thanks
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you
2006 Dec 06
2
validates_uniqueness_of where scope euqals created_by "magic" field
I have the following ActiveRecord objects:
class Recipe < ActiveRecord::Base
  has_many :ratings, :dependent => true
  . . .
end
class Rating < ActiveRecord::Base
  validates_uniqueness_of :created_by, :scope => :recipe_id
  belongs_to :recipe, :counter_cache => true
  . . .
end
The created_by field on Rating is implemented as a "magic" field
similar to this:
2006 Dec 09
1
validates_uniqueness_of serialize
ActiveRecord bug ?
  validates_uniqueness_of
doesn''t work with
  serialize
I''m trying to serialize, unserialize an Array-type property of a Object
instance,  and validate that the Array or serialized version is unique
within the the scope of another property using :scope
does anyone know a work around ?
Anthony Green
-- 
Posted via http://www.ruby-forum.com/.
2008 Aug 21
1
validates_uniqueness_of not working - urgent
I''m using restful_authentication to let users register and login.
Lately, however, I''m seeing multiple login and emails being created
even though I have validates_uniqueness_of as below:
user.rb
validates_uniqueness_of   :login, :email, :case_sensitive => false
mysql> select id, login, email, created_at, state from users;
2006 Oct 12
2
How do I test a unique index?
I have a loans table and a payments table. Each loan has_many payments. 
So far no problem.
Now, the payments table has a payment_number field, and each payment has 
a payment_number unique within that loan. For example, Loan A can have 
payment_numbers 0, 1, and 2 and Loan B can have payment_numbers 0, 1, 2, 
and 3 (but only one of each payment_number). I can enforce this with a 
unique index in
2007 Nov 18
1
validates_uniqueness_of question
Given three models: a design model, a votes model, and a users model
the problem is a user can only vote for a design once.
If I do a validates_uniqueness_of :user in the votes model that means
a user can only vote once, period.  What I want is to say a user can
only vote for a single design once.  Anyone know the best way to do
this?  Thanks.
JB
2008 Sep 02
2
validates_uniqueness_of in update
I have a problem with the usage of validates_uniqueness_of  that I
hope someone can help throw a light on. With a new record, this
validation works fine. But my problem came when I am updating a
record. I was not able do it because it tells me that field value
already exists. I was actually updating the value of other fields.
According to the documentation which says "When the record is
2007 May 06
1
validates_uniqueness_of (with :scope) doesn't seem to work?
I have a master record called ''project'' and a child record called
''agycode''. Obviously, agycode has a project_id FK. I wish to make the
"descr" field unique ONLY within the ''project_id'' ''scope''. Here are the key
pieces of information
Agycode fields (id, project_id, descr)
Here''s the declaration in the
2008 May 09
4
Validating Uniqueness From Two Database Tables?
Well, I''m working on adding a new type of user (organization) to my
application, using a different database table than the standard User
table (in the end, I think it works out being easier to deal with than
creating another column in the original User table for account type).
However, I''m running into a user registration problem.  I can register
both types of users fine,
2008 May 23
20
Rails validation is inefficient
Hi,
I have a User model, with a validates_uniqueness_of :login
The generated SQL for the validation is:
SELECT * FROM `users` WHERE (LOWER(users.login) = ''fernando'' AND
users.id <> 10001) LIMIT 1;
and it takes  0.13s to happen (my table has 10.000 rows)
When I use the EXPLAIN instruction on it, it shows that it will use the
primary_key as index, but this is not
2006 Sep 06
6
validates_presence_of question
Can I use validates_presence_of somehow if I want to check that at least 
one of 2 fields is not empty?
Thanks,
Dmitry
-- 
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
2009 Feb 07
5
before_save :strip_whitespace => saves with spaces
i used this private function for removing leading and trailing white
spaces from the values.that below function would be called before_save.
when i print the value after it strips.it prints string without any
spaces.but in the table fields it saves with spaces .
waht would be the problem.pls help me
class CompanyInfo < ActiveRecord::Base
before_save :strip_whitespace
def strip_whitespace
   
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:  Aspect has
already been taken
I don''t
2006 Aug 23
5
validation, concurrency, and transactions
Hi,
  Something has been bothering me about model validation:  how do I know that 
the database has not changed in between when I validate my model''s data, and 
when it actually gets saved to the database?  As a simple example, say I have 
a User model like:
class User
	validates_uniqueness_of :username
end
When this gets saved to the database, the validation code checks that there is 
2006 May 10
1
Validates_uniqueness_of multiple field combo?
Hello,
I am new to Ruby on rails and this is therefore probably trivial. Lets 
say I have 3 tables - users[id,name, age, ...], 
interests[id,name,description, ...], and finally a table 
user_interests[id,user_id,interest_id] to link a user to a set of 
interests. Now there is no problem to put validates_uniqueness_of :name 
in the user-model to ensure that I only have one Lenny, but how do I 
2010 Aug 28
1
validates_uniqueness_of missing in rails 3.0 rc2?
Has anybody noticed validates_uniqueness_of missing in rails 3.0 rc2? I''m not sure if this is a bug or I''m just doing something wrong.
Here''s what I''m doing.
Class 1:
class Title < ActiveRecord::Base
  validates_length_of     :language, :is => 3
  validates_uniqueness_of :language, :scope => :book_id
  validate                :language,
2009 Jun 17
2
validates_uniqueness_of fails on STI in Rails 2.3.2
I''ve got something like this:
class Position < ActiveRecord::Base
end
class CartItem < Position
    validates_uniqueness_of :product_id
end
When I try to save CartItem I get this error:
ArgumentError: wrong number of arguments (1 for 2)
  from
/home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:758:in
`exists?''
  from
2007 May 28
5
validates_uniqueness_of does not pass unit test
I am doing some very very basic unit testing. If I take away the
uniqueness validation, the tests pass. Could this be a bug in Edge
Rails?
--~--~---------~--~----~------------~-------~--~----~
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