Hello,
I am a bit confused as to how inheritance and polymorphic relationships
are supposed to work. In the polymorphism.py example, the engineers and
managers both have the same set of attributes: person_id, company_id,
name, description. If I change the example so that engineers have a
special_description but managers still have description, then it ceases
to work when I try to look at c.employees.
With this approach failing I attempted to create an inheritance
structure using filtered mapping (as described at
http://www.objectmatter.com/vbsf/docs/maptool/ormapping.html#MappingaClassInheritanceTree
). To do this I created a Person table that has the columns
person_id, name, description, special_description, type. Then I mapped
Engineer against select([Person.person_id, name, special_description])
(assigned to the var engineerSelect) and Manager against
select([Person.person_id, name, description]). The next step of the
plan was to create an ExtensionMapper that would create an Engineer or
Person depending on the value in the type column. I'm missing some
other pieces such as where I put the logic in that automatically
assigns a value to the type column (a before_insert function in the
mapper perhaps?) when its committed.
Anyway, this doesn't work when creating and committing objects as I get
an error something like "No column description is configured on
Mapper|Engineer|engineerSelect..." So should I just abandon this
approach?
Finally, I have one (hopefully) trivial question. In the same
polymorphic example (not that the polymorphism matters in this
question) each Person object has a company_id attribute. I'm not too
concerned with knowing the company_id of a Person so much as I am with
being able to get an actual company object. so if I have a person john,
i could say c = john.company and c would be an instance of a Company
object. Likewise, I'd like to be able to create a Person with the
constructor dave = Person(company=c) so that I never have to look at
the company_id. Can relation(... backref='company' ...) do this?
Thanks,
Michael
- [Sqlalchemy-users] Class Inheritance / Polymorphism Michael Carter
- Re: [Sqlalchemy-users] Class Inheritance / Polymorphis... Michael Bayer
- Re: [Sqlalchemy-users] Class Inheritance / Polymorphis... Michael Bayer
- Re: [Sqlalchemy-users] Class Inheritance / Polymor... Michael Carter
- Re: [Sqlalchemy-users] Class Inheritance / Pol... Michael Bayer
- Re: [Sqlalchemy-users] Class Inheritance /... Michael Carter
- Re: [Sqlalchemy-users] Class Inherita... Michael Bayer
- Re: [Sqlalchemy-users] Class Inhe... Michael Carter
- Re: [Sqlalchemy-users] Class ... Michael Carter
- Re: [Sqlalchemy-users] Class ... Michael Bayer
- Re: [Sqlalchemy-users] Class ... Michael Carter