zzzeek / test_sqlalchemy

0 stars 0 forks source link

Adding the possibility to 'traverse' relations through the list-property #447

Closed sqlalchemy-bot closed 17 years ago

sqlalchemy-bot commented 17 years ago

Issue created by Anonymous


Like in the file I will attach (inspired by #441), let's have persons that may have cars that may have accidents (person 1---N car 1 ---N accident). Person has a property named "cars" and car a property named "accidents" (self-explaining I guess).

I would like to have the possibility to fetch the accidents of one person using:

for accident in personInstance.cars.accidents:
    print accident

It is not possible now (at least, using this syntax and in only one select) because "cars" is a simple list. Maybe using a more intelligent and iterable structure?


Attachments: 447.py

sqlalchemy-bot commented 17 years ago

Michael Bayer (zzzeek) wrote:


also join() and a whole bunch of other ways to do this

sqlalchemy-bot commented 17 years ago

Michael Bayer (zzzeek) wrote:


sqlalchemy-bot commented 17 years ago

Michael Bayer (zzzeek) wrote:


its far clearer to just use regular python instead of implicit magic:

for car in personInstance.cars:
    for accident in car.accidents:
        print accident

if youre concerned about excessive selects, thats what eager loading / result set mapping is for.

sqlalchemy-bot commented 17 years ago

Anonymous wrote:


Testing script

sqlalchemy-bot commented 17 years ago

Changes by Michael Bayer (zzzeek): set state to "wontfix"

sqlalchemy-bot commented 17 years ago

Changes by Michael Bayer (zzzeek): set milestone to "blue sky"

sqlalchemy-bot commented 17 years ago

Changes by Michael Bayer (zzzeek): changed priority from "critical" to "minor"

sqlalchemy-bot commented 17 years ago

Changes by Anonymous: set attachment to "447.py"