similar to: Validate uniqueness on two columns

Displaying 20 results from an estimated 10000 matches similar to: "Validate uniqueness on two columns"

2006 Feb 17
2
validate uniqueness of two fields
I have Proposals and Members and Members can vote for a proposal only once. So, I have "Vote belongs_to :member, :proposal", but to make sure a member only votes once, I want to make sure that there isn''t a vote in the db with that member_id and proposal_id. I can just put the appropriate find in a vote.valid? but I wanted to make sure I wasn''t missing a nice rails
2007 Sep 02
2
problem validating uniqueness
I have validates_uniqueness_of :name in my model which works fine when creating a record but doesn''t work when I edit the record. In other words it won''t let me create a record with the same name but I can go in after and update the field without a problem. Why would this happen? -Mike --~--~---------~--~----~------------~-------~--~----~ You received this message because you
2005 Mar 10
2
NoMethodError in Event_type#create
I am new Ruby on Rails, so excuse me if my question seems pretty obvious. I am trying to validate uniqueness of a filed: class EventType < ActiveRecord::Base belongs_to :sport validates_uniqueness_of :event_type end When I run it, I get this error message: Showing /event_type/new.rhtml where line #27 raised undefined method `each'' for nil:NilClass <select
2006 Jan 20
3
Is there a way to validate a model w/o saving it?
I have some code in my controller which looks like this: if request.post? and @account.save and @user.save ... end and in my Account and User models I have many :validates, like so account.rb validates_presence_of :subdomain, :on => :create validates_uniqueness_of :subdomain, :on => :create, :message => "is already being used" validates_exclusion_of
2012 Oct 24
1
Uniqueness and sql serialize
Hi fellow programmers, I was looking for how to keep integrity in some financial transactions and I saw this "This could even happen if you use transactions with the ‘serializable’ isolation level." in the uniqueness page http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#method-i-validates_uniqueness_of. How this is possible with the serializablo
2009 Sep 25
12
uniqueness validation perplexity
I want to write a validate routine to check to enforce that a position must be unique in a category. (In another category, it doesn''t have to and shouldn''t need to be unique.) I write this code which works happily for new items: def position_in_category_not_unique @items = Item.find( :all, :conditions => [ "category_id = ? AND position = ?", category_id,
2006 Sep 12
4
ActiveRecord Validations - validates_uniqueness_of
Hello, I''m wanting to use Mocha and Stubba for my tests in place of the default Rails testing with fixtures. I have the following class: class Person < ActiveRecord::Base validates_uniqueness_of :email end and am wondering how I can test to ensure that the validates_uniqueness_of validation is running. Any ideas? -Jonathan
2006 Feb 07
2
validates_uniqueness_of case Sensitive
Is there a option to make validates_uniqueness_of Case Sensitive, if so what is it, if not then how to do it without writing my own function. Regards Suraj
2006 May 10
4
validates_uniqueness_of and create atomicity
Hi folks, I have a question regarding validates_uniqueness_of, and similar before-filter-like events attempting to guarantee some DB state prior to modification. >From my reading of ActiveRecord, validate_uniqueness_of appears to cause a SELECT on the underlying table attempting to ensure that a record with ID(s) specified in the validates_uniqueness_of statement is not already present, prior
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,
2006 Jun 29
0
How to validate uniqueness only if value exists
I''m looking for the best way to use validation to confirm that an optional field (hostname) is unique only if a value is entered in the form. I was originally following the path shown in Agile Web Development with Rails first edition, page 66, to define the "validate" method, but didn''t have a clue how to include a uniqueness test there. Right now, I have the
2006 Apr 14
8
Error with Web Service tests after upgrading to Rails 1.1.2
Hello. I hope this is the right place to describe my problem ? After upgrading to Rails version 1.1.2 from rails version 1.0.0, Web Service functional tests seem broken. I upgraded rails (as the root user / administrator) with: # gem update rails --include-dependencies then I upgraded my application (as myself) with: ? rake rails:update % rake rails:update:configs After these steps,
2006 Apr 14
1
Validating Existing Models
I''ve got a user object which has quite a few attributes mapped to the database. As of right now I''ve got some validations in the model like: validates_presence_of :password, :message => "You must specify a valid password." validates_confirmation_of :password, :message => "Password doesn''t match the confirmation." validates_presence_of
2007 Jan 01
5
Validations based on associations
My model is very simple, it''s mostly just a join table that represents which tournaments a user has registered for. class Registration < ActiveRecord::Base belongs_to :user belongs_to :tournament validates_presence_of :user_id, :tournament_id validates_uniqueness_of :user_id, :scope => :tournament_id end the validates_uniqueness checks to make sure there''s no
2006 May 31
3
validate unless, LoginGenerator difficulty
I apologize if this is a very simple question; I''ve searched the forums, wiki, Google, and Agile Web Development with Rails to no avail. Is there a way to put conditional validation in the model? For instance, if I want to limit items a user can add unless the user is an admin? My current code is: validates_uniqueness_of :user_id, :scope => ''event_id'',
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
2006 May 12
4
validates_uniqueness_of with a condition
Hi, I need to check the uniqueness of an attribute (a doc number) using a condition (a specific year), I''ve found validates_uniqueness_of :number, but I need to tell it I just want to check a specific year. I''ve found :scope but I haven''t really understood it''s meaning, Can I scope on a specific year? Thanks, Enrico -- "The only thing necessary for the
2005 Oct 15
7
You ASKED for an Asterisk book, you GOT an Asterisk book!
Jared Smith, Jim van Meggelen, and Leif Madsen of the Asterisk Documentation Project, in conjunction with O'Reilly Media are pleased to announce the official release of Asterisk: The Future of Telephony on Friday, October 14, 2005 at AstriCon 2005 in Anaheim, CA. In the true spirit of Open Source, the authors and O'Reilly Media have published the book under the open, Creative Commons
2007 Aug 23
6
controller spec with model that validates_uniqueness
I want to use mocks and stubs to test the controller, but am having trouble getting my validation not to trigger. Here''s the code: # spec: Image.stub!(:find).and_return(@image) @image.should_receive(:save!).once.with(:any_args) put :update, :id => @image.id, :category_id => @category.id, :image => {:name => ''test'', :image_number =>
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