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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Gomzi Pai at Dec 23, 2011 at 7:03 am
    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 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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Dharmdip Rathod at Dec 23, 2011 at 7:08 am
    It's not working !

    Gomzi Pai wrote in post #1037968:
    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
    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Dec 23, 2011 at 8:05 am

    On 23 December 2011 07:07, Dharmdip Rathod wrote:
    It's not working !
    It is no good just saying it is not working, what response do you
    expect from that?

    Gautam Pai suggested that you read the documentation, but four minutes
    later you posted your reply so I suspect you did not do that. Go back
    and read the documentation, check your code, try things in the rails
    console to try and work out what the problem is.

    Then if you still cannot get it to work show us the code ( just the
    relevant bits in the model where you specify the validation) and some
    results from saving records in the Rails Console that shows that it
    does not work.

    Colin
    Gomzi Pai wrote in post #1037968:
    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
    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


    --
    gplus.to/clanlaw

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Dharmdip Rathod at Dec 23, 2011 at 9:50 am
    I had already gone through. so my reply was quick.

    :)

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Dharmdip Rathod at Dec 23, 2011 at 10:03 am

    Dharmdip Rathod wrote in post #1037996:
    I had already gone through. so my reply was quick.

    :)
    By the way,

    Thanks All for quick reply and support.

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Bala kishore pulicherla at Dec 23, 2011 at 10:06 am
    validates :item_code, :presence => true, :uniqueness => { :scope => user_id}


    try this way

    On Fri, Dec 23, 2011 at 3:32 PM, Dharmdip Rathod wrote:

    Dharmdip Rathod wrote in post #1037996:
    I had already gone through. so my reply was quick.

    :)
    By the way,

    Thanks All for quick reply and support.

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 23, '11 at 6:28a
activeDec 23, '11 at 10:06a
posts7
users4
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase