your extension needs to translate the row being passed to the
descendant mapper, i.e. inside of populate_instance.  any dictionary
which has Column instances for keys will work.  such as:

    def populate_instance(self, mapper, selectcontext,
                          row, instance, identitykey, isnew):
        newmapper = class_mapper(type(instance))
        newrow = dict((k,row[k]) for k in list(employees.c))
        newrow[managers.c.manager_id] = row[employees.c.person_id]
        newrow[engineers.c.engineer_id] = row[employees.c.person_id]
        newmapper.populate_instance(selectcontext, instance, newrow,
                                 identitykey, isnew)
        return True


On Feb 1, 11:21 am, "King Simon-NFHD78" <[EMAIL PROTECTED]>
wrote:
> Hi again,
>
> I have a situation where I'd like to be able to load entities from a
> single table, but that have attributes defined in other tables,
> depending on their type (basically the same as the multiple table
> inheritance example in the docs), and I'd like all of the attributes
> that are defined in other tables to be lazily loaded, so my initial
> selection only queries the first table - no polymorphic unions or
> anthing.
>
> I've attached my initial attempt, which works for the simple case.
> However, I think the only reason it works is because the primary key
> columns on each table are named the same. If you rename
> engineers.person_id to engineers.engineer_id, for example, it fails when
> populating the instance because it can't find a value to populate the
> engineer_id property with. Even if the column is called person_id, the
> load fails if it is part of a bigger query (eg. an eager load from
> another object), because column aliases also break it.
>
> I played around with making the primary_key deferred as well, but that
> stops the deferred loading from working completely (probably not
> surprising really)
>
> I suppose a different way of doing this would be to map the attributes
> to a completely separate class, and then proxy them somehow on the main
> class, but I thought I would ask the question first, to see if anyone
> has any ideas.
>
> Thanks a lot,
>
> Simon
>
>  deferred_test.py
> 4KDownload


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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