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

94 questions
1
vote
2 answers

Testing the validation of uniqueness of the field in Rails's model using rspec without helper gems

I'm trying to write test to validate the uniqueness of the field in RoR's model. I am working on Ruby on Rails apps which I use to practice my skills in TDD. I have used Internet as my resource so far. I'm writing testing on validation for model.I…
1
vote
1 answer

Rails 3 validates_uniqueness_of with :scope generates invalid SQL?

Have two models that record some monthly statistics and I'm trying to enforce a composite key constraint within the model using: validates_uniqueness_of :entity_id, :scope => [:year, :month] When trying to run a .valid? method on a record, I…
1
vote
1 answer

Uniqueness validation not working on has_many :though association on rails 5

Models class User < ApplicationRecord has_many :memberships has_many :pages, through: :memberships end class Page < ApplicationRecord has_many :memberships has_many :users, through: :memberships end class Membership <…
user1682647
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
  • 9,220
  • 13
  • 44
  • 59
1
vote
1 answer

Validates uniqueness record per user per lesson // Rails 4

Problem: I want to have only 1 UserLesson per User per Video because I'm building a tracking system (progress system) User shall be able to see how many lessons are remaining lesson/total lesson and also when marked as completed shall add css I…
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
  • 5,994
  • 5
  • 42
  • 55
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,488
  • 9
  • 38
  • 67
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
  • 46,344
  • 73
  • 224
  • 412
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
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