aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/validations/uniqueness.rb
Commit message (Collapse)AuthorAgeFilesLines
* applies new doc guidelines to Active Record.Yves Senn2015-10-141-4/+5
| | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* uniqueness validation raises error for persisted record without pk.Yves Senn2015-08-201-1/+5
| | | | | | | | Closes #21304. While we can validate uniqueness for record without primary key on creation, there is no way to exclude the current record when updating. (The update itself will need a primary key to work correctly).
* Properly allow uniqueness validations on primary keys.Sean Griffin2015-07-251-1/+3
| | | | | | This is an alternate implementation of #20966. [Sean Griffin & presskey]
* Fix uniqueness validation with out of range valueAndrey Voronkov2015-04-081-0/+2
|
* `type_cast_for_database` -> `serialize`Sean Griffin2015-02-171-1/+1
|
* rm `Type#text?`Sean Griffin2015-02-071-1/+1
| | | | | | | | | | | | | | | | This predicate was only to figure out if it's safe to do case insensitive comparison, which is only a problem on PG. Turns out, PG can just tell us whether we are able to do it or not. If the query turns out to be a problem, let's just replace that method with checking the SQL type for `text` or `character`. I'd rather not burden the type objects with adapter specific knowledge. The *real* solution, is to deprecate this behavior entirely. The only reason we need it is because the `:case_sensitive` option for `validates_uniqueness_of` is documented as "this option is ignored for non-strings". It makes no sense for us to do that. If the type can't be compared in a case insensitive way, the user shouldn't tell us to do case insensitive comparison.
* Fix validations on child record when record parent has validate: falseeileencodes2015-02-011-0/+1
| | | | | | | | | | | | | | Fixes #17621. This 5 year old (or older) issue causes validations to fire when a parent record has `validate: false` option and a child record is saved. It's not the responsibility of the model to validate an associated object unless the object was created or modified by the parent. Clean up tests related to validations `assert_nothing_raised` is not benefiting us in these tests Corrected spelling of "respects" It's better to use `assert_not_operator` over `assert !r.valid`
* Remove most type related predicates from `Column`Sean Griffin2015-01-301-2/+3
| | | | | | Remaining are `limit`, `precision`, `scale`, and `type` (the symbol version). These will remain on the column, since they mirror the options to the `column` method in the schema definition DSL
* Don't rely on the column for type information in uniquness validationsSean Griffin2015-01-011-1/+2
| | | | The validator has access to richer type information
* Remove all cases of manuallly wrapping `Arel::Nodes::Quoted`Sean Griffin2014-12-291-1/+0
| | | | | | | | | | This is no longer required now that we are injecting a type caster object into the Arel table, with the exception of uniqueness validations. Since it calls `ConnectionAdapter#type_cast`, the value has already been cast for the database. We don't want Arel to attempt to cast it further, so we need to continue wrapping it in a quoted node. This can potentially go away when this validator is refactored to make better use of `where` or the predicate builder.
* Go through normal `where` logic in uniqueness validationSean Griffin2014-12-261-4/+6
| | | | | | | This code could use some much heavier refactoring. It looks like `build_relation` duplicates most of the logic of `Relation#where` and `PredicateBuilder` with regards to handling associations and attribute aliases
* We don't need to cast the value a second time in uniqueness validationsSean Griffin2014-12-261-0/+1
| | | | | | | Part of the larger refactoring to remove type casting from Arel. Since we've already cast the value a few lines above, we don't need to re-cast it later. We can inform Arel of this by wrapping it in an `Arel::Nodes::Quoted`, which will no longer be required in Rails 5.1
* Correctly ignore `case_sensitive` for UUID uniqueness validationSean Griffin2014-12-261-1/+1
| | | | | | | | I think we should deprecate this behavior and just error if you tell us to do a case insensitive comparison for types which are not case sensitive. Partially reverts 35592307 Fixes #18195
* Improve the performance of reading attributesSean Griffin2014-11-181-1/+1
| | | | | | | We added a comparison to "id", and call to `self.class.primary_key` a *lot*. We also have performance hits from `&block` all over the place. We skip the check in a new method, in order to avoid breaking the behavior of `read_attribute`
* [ci skip] fix doc typo for validates_uniqueness_ofSatoru Yamasaki2014-07-291-1/+1
|
* Remove the `text?` predicate from the type objectsSean Griffin2014-07-061-2/+4
| | | | | | | This was only used for uniqueness validations. The first usage was in conjunction with `limit`. Types which cast to string, but are not considered text cannot have a limit. The second case was only with an explicit `:case_sensitive => true` option given by the user.
* Don't rely on the column for type casting reflectionsSean Griffin2014-06-181-1/+1
|
* Remove most code related to serialized propertiesSean Griffin2014-06-011-7/+0
| | | | | | | | | | | Nearly completely implemented in terms of custom properties. `_before_type_cast` now stores the raw serialized string consistently, which removes the need to keep track of "state". The following is now consistently true: - `model.serialized == model.reload.serialized` - A model can be dumped and loaded infinitely without changing - A model can be saved and reloaded infinitely without changing
* Merge pull request #15210 from arthurnn/fix_hbtm_reflectionArthur Neves2014-05-241-2/+2
| | | | | | | | | Fix habtm reflection Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/counter_cache.rb activerecord/lib/active_record/reflection.rb activerecord/test/cases/reflection_test.rb
* Follow up to bbe7fe41 to fix enum leakage across classes.Godfrey Chan2014-04-071-1/+1
| | | | | | | | The original attempt didn't really fix the problem and wasn't testing the problematic area. This commit corrected those issues in the original commit. Also removed the private `enum_mapping_for` method. As `defined_enums` is now a method, this method doesn't provide much value anymore.
* Merge pull request #13040 from kamipo/case_sensitive_comparisonRafael Mendonça França2014-03-121-2/+1
|\ | | | | | | | | | | | | Only use BINARY for mysql case sensitive uniqueness check when column has a case insensitive collation. Conflicts: activerecord/CHANGELOG.md
| * Only use BINARY for mysql case sensitive uniqueness check when column has a ↵Ryuta Kamizono2013-11-261-2/+1
| | | | | | | | case insensitive collation.
* | WhitespacesRafael Mendonça França2014-03-101-2/+2
| |
* | Fix a bug affecting validations of enum attributesTheMonster2014-02-271-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a bug where any enum attribute of a model would be evaluated always as 0 when calling the database on validations. This fix converts the value of the enum attribute to its integer value rather than the string before building the relation as the bug occured when the string finally gets converted to integer using string.to_i which converts it to 0. [Vilius Luneckas, Ahmed AbouElhamayed]
* | Cleanups in API docs: his => theirGuillermo Iguaran2013-12-021-2/+2
| |
* | Use genderless pronouns in API docsGuillermo Iguaran2013-12-011-1/+1
| |
* | Merge pull request #13061 from ↵Rafael Mendonça França2013-11-261-1/+9
|/ | | | | | | | laurocaetano/fix-uniqueness-validation-for-aliased-attribute Fix bug when validating the uniqueness of an aliased attribute. Conflicts: activerecord/CHANGELOG.md
* Fix validation on uniqueness of empty associationEvgeny Li2013-11-221-1/+1
|
* replace artificial space with RDoc markup (follow up #11285). [ci skip]Yves Senn2013-07-041-2/+2
|
* [ci skip] Separated full stop from the Optimistic_concurrency_control wiki ↵ankit88982013-07-041-1/+1
| | | | link d4e3f8ba826cd42aa3c242149
* deprecate Validator#setup (to get rid of a respond_to call). validators do ↵Nick Sutterer2013-05-231-6/+1
| | | | their setup in their constructor now.
* Change uniq validation with conditions examples to use where with hashesCarlos Antonio da Silva2013-03-091-3/+3
| | | | Take the opportunity to showcase where.not.
* Uniqueness validation uses a proc to specify the `:conditions` option.Yves Senn2013-03-091-3/+7
| | | | | This is a follow up to #5321 and follows the general direction in AR to make things lazy evaluated.
* Extract some methodsCarlos Antonio da Silva2012-12-181-16/+22
|
* Change relation in placeCarlos Antonio da Silva2012-12-181-1/+1
|
* Simplify value logic by always typecastingCarlos Antonio da Silva2012-12-181-11/+5
|
* Avoid unnecessary hashes with error optionsCarlos Antonio da Silva2012-12-181-1/+4
|
* Remove prepend_and_append requirement from ASCarlos Antonio da Silva2012-12-181-3/+1
| | | | It's not necessary to use this extension here, we are fine with Array#unshift.
* Refactor uniqueness validator logic a bitCarlos Antonio da Silva2012-12-181-10/+5
| | | | | Cleanup some code, avoid extra hash with reverse_merge, and don't use send for :id, since it's always present.
* Added support for validates_uniqueness_of in PostgreSQL array columns. ↵Pedro Padron2012-12-181-1/+6
| | | | Fixes: #8075.
* refactoring of uniqueness validate_eachAngelo Capilleri2012-10-141-1/+2
| | | | get scope_value only one time dependig on reflection
* small refactoring of build_relation in uniquenessAngelo Capilleri2012-09-291-5/+3
| | | | | reflection init as 'if' stantment. column is always the same expression and depends from the changing of attributes
* update AR::Validations documentation [ci skip]Francesco Rodriguez2012-09-221-6/+6
|
* update AR::Validations::UniquenessValidator documentation [ci skip]Francesco Rodriguez2012-07-291-31/+45
|
* Fixes "Cannot visit ..." with validates_uniqueness_ofbeerlington2012-07-171-1/+1
| | | | | | Fixes issue with overrding ActiveRecord reader methods with a composed object and using that attribute as the scope of a validates_uniqueness_of validation.
* fix tests for SQLite3AdapterAndrey Deryabin2012-04-271-1/+0
|
* Correct grammar in documentationMattias Pfeiffer2012-03-071-1/+1
|
* Change syntax to accept an AR::Relation instead of old conditions hash/array.Mattias Pfeiffer2012-03-071-3/+9
|
* Add :conditions option to uniqueness validatorMattias Pfeiffer2012-03-071-2/+12
|
* say unshift when you mean unshift (modulus prepend)Xavier Noria2012-02-111-1/+3
|