You can scope a validates_uniqueness_of
call as follows.
validates_uniqueness_of :user_id, :scope => :friend_id
More Related Contents:
- How to chain scope queries with OR instead of AND?
- ActiveRecord Find By Year, Day or Month on a Date field
- Rails – Validate Presence Of Association?
- ActiveRecord OR query
- ActiveRecord: size vs count
- Eager load polymorphic
- accepts_nested_attributes_for with find_or_create?
- Rails 3: “field-with-errors” wrapper changes the page appearance. How to avoid this?
- ActiveRecord OR query Hash notation
- Rails order by results count of has_many association
- When to use a “has_many :through” relation in Rails?
- Rails 3: Get Random Record
- Rails 5: ActiveRecord OR query
- Setting session timeout in Rails 3
- Clean way to find ActiveRecord objects by id in the order specified
- Rails 3 SQLite3 Boolean false
- Rails 3, has_one / has_many with lambda condition
- Rails update_attributes without save?
- Rails 3 – select with Include?
- query , can not select column count
- belongs_to through associations
- Check if record exists from controller in Rails
- Creating a PostgreSQL sequence to a field (which is not the ID of the record)
- Why use “self” to access ActiveRecord/Rails model properties?
- How to implement bulk insert in Rails 3
- PGError: ERROR: aggregates not allowed in WHERE clause on a AR query of an object and its has_many objects
- Ruby on Rails Callback, what is difference between :before_save and :before_create?
- Controlling the order of rails validations
- Specifying column name in a “references” migration
- Rails: Order with nulls last