Topic: validates_uniqueness_of can't be class agnostic?
I've got a table full of users and I'm trying to use validates_uniqueness_of on the username column. All records are from derived STI classes but I put most of the model definition into the parent User class:
class User < ActiveRecord::Base
class Writer < User
class Reader < User
I'm attempting to get this validation check to work at the topmost scope, but it's not working:
w = Writer.new
w.username = 'danger'
w.save # => true
r = Reader.new
r.username = 'danger'
r.save # => true
ActiveRecord is automatically assigning the scope to my derived class:
Writer Load (0.015708) SELECT * FROM users WHERE (users.username = 'danger') AND ( (users.`type` = 'Writer' ) ) LIMIT 1
Reader Load (0.015708) SELECT * FROM users WHERE (users.username = 'danger') AND ( (users.`type` = 'Reader' ) ) LIMIT 1
I've tried using
validates_uniqieness_of :username, :scope => nil
but that doesn't do anything. Any ideas how to work around this issue?
Last edited by danger (2006-08-25 21:12:01)