can you just
    validate_uniqueness_of :name, conditions: -> { where 'user_id is not null' }, on: create
or something