This project is archived and is in readonly mode.
validates_uniqueness_of does not take field length into account
-
Arthur Klepchukov
Sorry, the second part got mangled. Here it is again.
I can do something along the lines of:
>> e = Event.create(:title => "abcde") => #<Event id: 1, title: "abcde", description: nil, time: nil, created_at: "2008-09-14 09:01:14", updated_at: "2008-09-14 09:01:14"> >> e2 = Event.create(:title => "abcdefgh") => #<Event id: 2, title: "abcdefgh", description: nil, time: nil, created_at: "2008-09-14 09:01:31", updated_at: "2008-09-14 09:01:31"> >> Event.find_all_by_title("abcde") => [#<Event id: 1, title: "abcde", description: nil, time: nil, created_at: "2008-09-14 09:01:14", updated_at: "2008-09-14 09:01:14">, #<Event id: 2, title: "abcde", description: nil, time: nil, created_at: "2008-09-14 09:01:31", updated_at: "2008-09-14 09:01:31">] -
Arthur Klepchukov
I realize that this could be taken care of if I set validates_length_of :title, :maximum => 5 in my model. However, I don't like having to repeat that (since I specified it in the migration) and I'm still worried about the database being in an inconsistent state.
A basic fix to this could be adding the following after line 669 in lib/active_record/validations.rb:
value = value[0, finder_class.columns_hash[attr_name.to_s].limit] -
Arthur Klepchukov
I went ahead and submitted a patch.
-
Pratik
- Assigned user set to Pratik
- State changed from new to incomplete
That's a good catch and it looks very tricky as well.
I can't see any patch. Could you please upload a patch here - http://rails.lighthouseapp.com/p... ?
Thanks.
-
Arthur Klepchukov
- Tag changed from activerecord, bug, migrations to activerecord, bug, limit, migrations, validates_uniqueness_of, validation
This patch makes ActiveRecord's validates_uniqueness_of take :limit into account for :string columns.
-
Arthur Klepchukov
- Tag changed from activerecord, bug, limit, migrations, validates_uniqueness_of, validation to activerecord, bug, limit, migrations, patch, validates_uniqueness_of, validation
Tagged as patch.
-
Pratik
- State changed from incomplete to open
-
Daniel Schierbeck
Nice patch, with good, concise comments and a simple-to-follow test. +1.
-
Repository
- State changed from open to resolved
(from [ccb0a92fa2ba0bf7be50033090c3a861e6d907be]) Ensure validates_uniqueness_of considers limit on the field. [#1042 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...
-
Jacob Burkhart
This needs to be fixed to support unicode, see #2653
