Hi All!
Assume we have the following setup:

a_table = Table('A', metadata,
                Column('id', Integer, primary_key=True)
                )

b_table = Table('B', metadata,
                Column('id', Integer, primary_key=True),
                Column('parent_b1_id', Integer, ForeignKey('B.id')),
                Column('parent_a_id', Integer, ForeignKey
(a_table.c.id)),
                Column('parent_b2_id', Integer, ForeignKey('B.id')))

mapper(A,a_table)
mapper(B,b_table,properties = {
    'parent_b1': relation(B,
                     lazy = True,
                     remote_side = [b_table.c.id],
                     join_depth = 1,
                     primaryjoin = (b_table.c.parent_b1_id ==
b_table.c.id)),
    'parent_z': relation(A,lazy = True),
    'parent_b2': relation(B,
                     lazy = True,
                     remote_side = [b_table.c.id],
                     join_depth = 1,
                     primaryjoin = (b_table.c.parent_b2_id ==
b_table.c.id))
});

#and lets do perform a query:
session.query(B).options(eagerload('parent_b1'),eagerload
('parent_b2'),eagerload('parent_z')).all()

#the query gives us the following output (MySQL)

"""
SELECT ...
FROM `B`
LEFT OUTER JOIN `B` AS `B_1` ON `B`.parent_b1_id = `B_1`.id
LEFT OUTER JOIN `B` AS `B_2` ON `B_1`.parent_b2_id = `B_2`.id
LEFT OUTER JOIN `A` AS `A_1` ON `A_1`.id = `B_2`.parent_a_id
"""

Take a look at the last join - it gives me the B->B_2-A, but I asked
for  B-A,

BTW, note this 'parent_z' notation, change to 'parent_a' and you will
get the following joins:

LEFT OUTER JOIN `A` AS `A_1` ON `A_1`.id = `B`.parent_a_id
LEFT OUTER JOIN `B` AS `B_1` ON `B`.parent_b1_id = `B_1`.id
LEFT OUTER JOIN `B` AS `B_2` ON `B_1`.parent_b2_id = `B_2`.id

Now the last join gives me B->B_1->B->2 instead of B->B_2

I tried but could not change this behavior, except turning Lazy off,
is there something I miss or it's a bug?

P.S.
I'm using sqlalchemy 0.5 rc4, db server MySQL







--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to