hi -

theres a lot of subtle details to this sort of thing, but something to
keep in mind is that creating a union of two tables and creating a mapper
against that union, *is* a filtered approach.  the unioned select is
essentially a rowset that consists of both manager and engineer rows, just
like a single table.  If you want to have different column names in them,
then your union has to account for all of those column names, and your
MapperExtension has to translate column names appropriately. 
MapperExtension can do this in create_instance or also append_result.

also the error you get about "no column "description" ", while its not
very meaninful without a stack trace, might suggest that you didnt set up
"plain vanilla" mappers on your classes first with which to handle the
saving of the objects....this wacky "polymorphic" mapper is used only to
load objects.  Basically, the test is, you should be able to load and save
objects of all desired types completely, before your code ever defines any
kind of polymorphic mapper or MapperExtension.

as always, small code examples are very helpful as i (or perhaps
others....anyone? ) can often illustrate the changes needed to make them
work.





Michael Carter wrote:
> 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
>



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to