Questions tagged [validates-uniqueness-of]

validates_uniqueness_of is a rails helper method for determining whether an attribute is unique throughout a system

In Ruby on Rails, the validates_uniqueness_of method determines whether an attribute is unique across a system.

http://apidock.com/rails/v4.2.1/ActiveRecord/Validations/ClassMethods/validates_uniqueness_of

90 questions
1
vote
1 answer

How to use validates_uniqueness_of an id but only for some items out of a list of items with the same id. rails

I have two drop down lists. One that contains items with bmp_id and a sublist that includes items with that bmp_id (in this case it is 2) that each have a unique bmpsublist_id. One of the options from the main dropdown list includes five sublist…
1
vote
2 answers

Rails - Custom validation of uniqueness

I want to impart uniqueness on a column (type string), however the problem is on some of the strings I'm truncating part of the beginning before inserting them into the database using a function and before_save. Thus the rails uniqueness validation…
acqwctm
  • 27
  • 5
1
vote
1 answer

Hibernate - a different object with the same identifier value was already associated with the session

Possible Duplicate: Spring + Hibernate : a different object with the same identifier value was already associated with the session After changing the @id of a Entity from @Id private int getId(){ return this.id; } to @Id private String…
Michel
  • 8,310
  • 13
  • 41
  • 56
1
vote
2 answers

MongoId combined uniqueness index

I have three models class Org include Mongoid::Document field :name, type: String embeds_many :org_groups end class OrgGroup include Mongoid::Document field :name, type: String embedded_in :org has_and_belongs_to_many…
1
vote
1 answer

rspec mongoid validation of uniqueness

I would like to test the uniquness of User model. My User model class looks like: class User include Mongoid::Document field :email, type: String embeds_one :details validates :email, presence: true, uniqueness: true, …
Mark
  • 4,802
  • 5
  • 36
  • 50
1
vote
1 answer

How do I validate_uniqueness_of when scoped to two attributes only when one attribute on matching existing records does not equal a specific value?

I have an Invitation model that represents an invitation to join a subscription. There should only be one Invitation at any given time with a specific email / subscription_id combination unless the other records with the matching email /…
1
vote
1 answer

Core Data uniqueness

Is there any way I can validate a value updated in a Core Data entity's property against values of the property in other entities in the collection? At the moment I create an entity with some default values, add it to arrangedObjects, then get the…
codedog
  • 2,368
  • 9
  • 36
  • 65
1
vote
0 answers

Setting up message for validation rules

I have this validation rule: validates :email, :presence => {:message => 'Email cannot be blank.'}, :allow_blank => true, :format => {:with => /\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/, :message => 'Email is not valid.'}, :uniqueness =>…
user984621
  • 41,002
  • 66
  • 200
  • 371
1
vote
1 answer

Ruby validates_uniqueness_of email leading to wrong SQL uniqueness check

I am seeing the following SQL being used to check that an email address (e.g. joebloggs@joebloggs.com) is unique when a user signs up on my Ruby website: SELECT `users`.id FROM `users` WHERE (`users`.`email` = BINARY '---…
Neil
  • 21
  • 3
1
vote
1 answer

validate on an attribute and has_many through relationship

i have the following structure: class FundFilter < ActiveRecord::Base has_many :fund_filter_users, dependent: :destroy has_many :users, through: :fund_filter_users end class FundFilterUser < ActiveRecord::Base belongs_to :fund_filter …
1
vote
1 answer

Rails accepts_nested_attributes for: eliminating duplicates

Say we've got the following models: class User < ActiveRecord::Base has_many :widgets accepts_nested_attributes_for :widgets, allow_destroy: true end class Widget < ActiveRecord::Base belongs_to :user validates :title, presence:…
scttnlsn
  • 2,754
  • 1
  • 28
  • 36
1
vote
2 answers

RoR EMail Validations--Multiple Regexes/formats

I am trying to use validates_format_of in my model file to validate an email address. However, I need to enter two regexes for two special cases. Basically, only a few top-level domain names are allowed. However, it seems according to the source…
thepervysage
  • 27
  • 1
  • 3
1
vote
2 answers

Rails validate uniqueness of attribute according to another table

I have a model User, which has_many Profile. I also have Report model, which belongs_to Profile. How can I make sure that one user has only one report? Something like class Report validate_uniqueness_of profile_id, scope: :user end would be…
AdamNYC
  • 17,771
  • 28
  • 90
  • 147
1
vote
0 answers

custom uniqueness validation with rails

I am trying to make a custom validator for uniqueness. The following example does not work for some reason: validates :language_id, uniqueness: { scope: :country_id}, if: :no_detail? validates :language_id, uniqueness: { scope:…
Alex C
  • 1,284
  • 2
  • 17
  • 40
1
vote
2 answers

Rails: Validates uniqueness of scoped by date

I have a Rails model that should only allow saving/updating of a model once per day per user. I have a callback to do the Find by user and date then add to errors but this is ugly and feels un-rails-like. I have the typical created_at / updated_at…
Matt Rogish
  • 22,940
  • 11
  • 72
  • 92