On Jul 9, 2007, at 10:53 PM, Patrick McKinnon wrote:
> ...
if you need this to just work, the easiest to do this mapping is the
normal way, i.e. using a property for "attributes" on Parent. getting
a directly mapped property to work is the most ambitious. heres a
simple way to do it, there are others that are more query based.
class Parent(object):
@property
def attributes(self):
for child in self.children:
for attr in child.attributes:
yield attr
mapper(
Parent,
parent_table,
properties = dict(
children = relation(Child, backref='parent'),
))
child_mapper = mapper(
Child,
child_table)
attribute_mapper = mapper(
Attribute,
attribute_table,
properties = dict(
child = relation(Child, backref=backref('attributes')),
)
)
this actually isnt even much of a performance issue since you can
eagerly load Child and Attribute together, compressing it into one
query.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---