try :scope option in your statement eg:
validates :itemcode, :uniqueness => true, :scope => :user_id read the documentation here http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#method-i-validates_uniqueness_of and section 3.10 uniqueness in http://guides.rubyonrails.org/active_record_validations_callbacks.html Gautam Pai On Fri, Dec 23, 2011 at 11:57 AM, Dharmdip Rathod <[email protected]>wrote: > Hi All, > > I am facing sort of problem while validating . > > Two models User & Product. > > class User < ActiveRecord::Base > has_many :products, :dependent => :destroy > end > > class Product < ActiveRecord::Base > belongs_to :user > validates :itemcode, :uniqueness => true > end > > Now case, > > System has number of users who can insert product information with > itemcode > uniqueness, but we need uniqueness validation with user_id and > itemcode.System need to check join table validation for new item with > user_id and itemcode. > > Please suggest. > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

