Hi all,
I want to use session.query(...).options(joinedload('*')) to load all
related objects eagerly.
It seems not to work if inheritance is involved.
This is a complete working example using SQLAlchemy 0.7.7 and Elixir
0.8.0dev:
---------------------
from elixir import *
from sqlalchemy import create_engine
from sqlalchemy.orm import joinedload
engine = create_engine('sqlite:///:memory:', echo = False)
metadata.bind = engine
class PersistentObject(Entity):
pass
class Movie(PersistentObject):
title = Field(Unicode(30))
director = ManyToOne('Director', inverse = "movies")
class Director(PersistentObject):
name = Field(Unicode(60))
movies = OneToMany('Movie', inverse = "director")
setup_all(True)
rscott = Director(name=u"Ridley Scott")
alien = Movie(title=u"Alien")
brunner = Movie(title=u"Blade Runner")
rscott.movies.append(brunner)
rscott.movies.append(alien)
session.commit()
print "without joinedload"
session.close_all()
d = session.query(Director).first()
for i in session: print i
print "with joinedload"
session.close_all()
d = session.query(Director).options(joinedload('*')).first()
for i in session: print i
------------------
The last line should also print the movies, which does not happen.
When you set Entity as the baseclass of Movie and Director it works.
Is this a bug or is there a reason I don't see?
Thx in advance,
alex
--
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.