attached is a patch to the polymorph.py example that changes the name of
the column in the "engineers" table from "description" to
"special_description", adjusts the union'ed select for the different
column name and puts a quick column translation in the MapperExtension to
make the selection still work.

this example still doesnt get us into really flexible territory, such as,
the engineers/managers table having large sets of different columns, which
you would not want to exist on the opposite object...for stuff like that i
probably need to add some more hooks to MapperExtension.

it also seems like I might want to throw a more automated way to union
mappers together to acheive this same effect.



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
>

Attachment: poly.diff
Description: Binary data

Reply via email to