
No duck typing for properties in single table inheritance
Reported by Brian P O'Rourke | November 21st, 2009 @ 05:51 PM
Brought up in IRC today, this is more of an annoyance than a bug. Duck typing isn't possible with properties of subclasses in single-table-inheritance...
class Order
include DataMapper::Resource
property :type, Discriminator
end
class Debit < Order
property :refunded, Boolean
end
# This works fine:
Debit.all.each |d|
puts d.refunded
end
# This should be possible but will fail:
Order.all.each |o|
puts o.refunded if o.type == Debit
end
A workaround is to declare all properties on the superclass, but this is an annoyance. Subclasses should be able to have properties independent of their parents.
Comments and changes to this ticket
-
Steve Tooke (tooky) January 11th, 2010 @ 06:32 PM
We've seen this exact bug, and the workaround has got us going.
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »