Thanks for the replies; I think I'm going in the right direction now.

Polymorphic association looks almost exactly like what I'm wanting to
do but, for now I changed the requirements to something simpler that
should just be an association object pattern.


The weird thing is, I only ever get one result even though multiple
results should exist...

base_table = Table('base_type', metadata,
    Column('id', types.Integer, primary_key=True, autoincrement=True),
    Column('name', types.String(255)))

relations_table = Table('relations', metadata,
    Column('toObj', types.Integer, ForeignKey('base_type.id')),
    Column('fromObj', types.Integer, ForeignKey('base_type.id')),
    Column('how', types.String(255), default=''))

class BaseType(object):
    pass

class Relation(object):
    pass

mapper(BaseType, base_table, properties={
    'relations': relation(Relation,
        primaryjoin=relations_table.c.fromObj==base_table.c.id)
})

mapper(Relation, relations_table, properties={
    'child': relation(BaseType,
        primaryjoin=base_table.c.id==relations_table.c.toObj)
}, primary_key=[relations_table.c.fromObj])


I have three rows in the base_table (id's 1-3) and two rows in the
relations table.
So the row with id 1 in the base_table is linked to the other two rows
view two entries in the relations table:
INSERT INTO relations (toObj, fromObj) VALUES (2, 1);
INSERT INTO relations (toObj, fromObj) VALUES (3, 1);

I do a query on BaseType to get the first row, and then iterate over
it's relations:
for obj in base.relations:
    print obj.child.name

And I only get one (the first entered relation) output... seems I
should be getting two?


--~--~---------~--~----~------------~-------~--~----~
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