here's a pastebin of it:

http://pastebin.com/z8XWsv2e


On Aug 16, 2011, at 7:42 PM, Michael Bayer wrote:

> 
> On Aug 16, 2011, at 5:37 PM, Mike Gilligan wrote:
> 
>> I have a single table that looks similar to the following:
>> 
>> class Equipment(Base):
>>     type = Column(CHAR(1), primary_key=True)
>>     sub_type = Column(CHAR(1), primary_key=True)
>>     code = Column(CHAR(5), primary_key=True)
>> 
>> 
>> For historical purposes, I cannot modify this table. I would like to setup 
>> multi-level inheritance similar to this, however it does not work:
>> 
>> class Equipment(Base):
>>     type = Column(CHAR(1), primary_key=True)
>>     sub_type = Column(CHAR(1), primary_key=True)
>>     code = Column(CHAR(5), primary_key=True)
>>     __mapper_args__ = {'polymorphic_on': type}
>> 
>> 
>> class Vehicle(Equipment):
>>      __mapper_args__ = {'polymorphic_identity': 'V', 'polymorphic_on': 
>> sub_type}
>> 
>> 
>> class Bus(Vehicle)
>>      __mapper_args__ = {'polymorphic_identity': 'B'}
>> 
>> 
>> class Rail(Vehicle)
>>      __mapper_args__ = {'polymorphic_identity': 'R'}
>> 
>> 
>> I can concatenate the multiple column values into a single discriminator 
>> column_property but then I do not have an easy way to retrieve all vehicles. 
>> Any ideas?
> 
> The inheritance querying does handle multi-level inheritance so if your 
> discriminator was on a concatenation of both things would work just fine, 
> i.e. if you queried for Vehicle, etc.   Each object's "polymorphic_identity" 
> would need to include the concatenated value, of course.
> 
> Unfortunately we're just beginning to support inheritance discriminators on a 
> column_property(), and you need to use a very specific approach to make this 
> work right now.  There's some tickets in trac to allow this functionality out 
> of the box.    Attached is an example script which exercises the above 
> mapping - it uses declarative to minimize the impact of the workaround.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 
> 
> 
> 
> 
> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "sqlalchemy" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/sqlalchemy/-/qNSg1VvOrWwJ.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to 
>> [email protected].
>> For more options, visit this group at 
>> http://groups.google.com/group/sqlalchemy?hl=en.
> 
> <multi_discrim.py>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to