#648 ✓resolved
Greg Campbell

Potentially incorrect scope for STI uniqueness validation

Reported by Greg Campbell | November 10th, 2008 @ 06:29 PM | in 0.10.0

class Person
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :unique => true

  property :type, Discriminator

class Man < Person; end
class Woman < Person; end

man = Man.new(:name => "Pat")

woman = Woman.new(:name => "Pat")
woman.valid? # => true

man2 = Man.new(:name => "Pat")
man2.valid? # => false

In my opinion, a uniqueness validation on a shared property specified at the level of the parent class ought to validate against the entire table for all child instances. The SQL for the uniqueness check here, however, looks like: SELECT id FROM people WHERE (type IN ('Woman')) AND (name = 'Pat') ORDER BY id LIMIT 1.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »