I have two rails Active Record models groups and accounts
group
has_many :accounts
id
name
.. other infromation
timestamps
Account
belongs_to :group
id
name
.. other information
timestamps
I need to do a validates :name, :uniqueness => true in the accounts section but only under a group. As in i want the account name to be unique under a group. I know i can enforce a database unique constraint but can i do this using AR ? Is it even possible ?
Try this:
For more information on the options available to validate, check out the ActiveRecord Validations documentation.