validate_uniqueness_of question


I've only used multiple column in indexes when scoping relationships like the following:

    create_table :accounts, :force => true do |t|       t.column :name, :string, :null => false, :limit => 50       ...     end

    create_table :users, :force => true do |t|       t.column :account_id, :integer, :null => false       t.column :email_address, :string       ...     end

    add_index :users, [ :account_id, :email_address ], :unique => true

Then you can use:

    validates_uniqueness_of :email_address, :scope => :account_id, :message => 'There is already another user with this email address.'

It sounds like if your PK is made of two columns you might want to just override before_validation(). Rails has never had great composite key functionality although I think there are some plugins out there that might ease the pain...

Hope this helps.