{"action":"opened","issue":{"url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/172","repository_url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project","labels_url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/172/labels{/name}","comments_url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/172/comments","events_url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/172/events","html_url":"https://github.com/ga-wdi-boston/full-stack-project/issues/172","id":137399040,"number":172,"title":"(Rails) Check Table for uniqueness under condition.","user":{"login":"erdesi90562","id":12851296,"avatar_url":"https://avatars.githubusercontent.com/u/12851296?v=3","gravatar_id":"","url":"https://api.github.com/users/erdesi90562","html_url":"https://github.com/erdesi90562","followers_url":"https://api.github.com/users/erdesi90562/followers","following_url":"https://api.github.com/users/erdesi90562/following{/other_user}","gists_url":"https://api.github.com/users/erdesi90562/gists{/gist_id}","starred_url":"https://api.github.com/users/erdesi90562/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erdesi90562/subscriptions","organizations_url":"https://api.github.com/users/erdesi90562/orgs","repos_url":"https://api.github.com/users/erdesi90562/repos","events_url":"https://api.github.com/users/erdesi90562/events{/privacy}","received_events_url":"https://api.github.com/users/erdesi90562/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-29T22:28:04Z","updated_at":"2016-02-29T22:28:04Z","closed_at":null,"body":"pseudo code\r\nUsers--<Lists--<Items (relationships)\r\n\r\nI would like guidance on how to check for uniqueness on a column when X condition is met.\r\n\r\nCheck list category for uniqueness Where :user_id = 'id'. If category = new category then enforce uniqueness or deny entry.\r\n \r\nI think I am close but I might not be understanding the interworking of ....\r\n```ruby\r\nclass List < ActiveRecord::Base\r\n  #validates :list, uniqueness: true #, if: params[:user_id].present?\r\n  validates_uniqueness_of :list, scope: :user_id                               # ...... of this line.\r\n  has_many :items, inverse_of: :list, foreign_key: :list_id\r\n  belongs_to :user\r\nend\r\n```"}}