here's the ticket: https://bitbucket.org/zzzeek/sqlalchemy/issue/3037/support-setting-load-options-on-instances
On Apr 28, 2014, at 1:38 PM, Michael Bayer <mike...@zzzcomputing.com> wrote: > it can be done with some API tinkering and I totally wrote this up for > someone recently, and cannot find it. > > This is not a public thing and isn't covered by tests, however this should be > a first class feature, if someone wants to work on it or propose a ticket or > whatnot. The intricate part is sending the right kind of load option at the > end, here's a simple one. > > from sqlalchemy import * > from sqlalchemy.orm import * > from sqlalchemy.ext.declarative import declarative_base > > Base = declarative_base() > > class A(Base): > __tablename__ = 'a' > > id = Column(Integer, primary_key=True) > bs = relationship("B") > > class B(Base): > __tablename__ = 'b' > > id = Column(Integer, primary_key=True) > a_id = Column(Integer, ForeignKey('a.id')) > cs = relationship("C") > > class C(Base): > __tablename__ = 'c' > > id = Column(Integer, primary_key=True) > b_id = Column(Integer, ForeignKey('b.id')) > > e = create_engine("sqlite://", echo=True) > Base.metadata.create_all(e) > > sess = Session(e) > sess.add_all([ > A(bs=[ > B(cs=[C(), C()]), > B(cs=[C(), C()]) > ]) > ]) > sess.commit() > > a1 = sess.query(A).first() > inspect(a1).load_options = inspect(a1).load_options.union([joinedload(B.cs)]) > > for b in a1.bs: > print b.cs > > > > On Apr 28, 2014, at 1:08 PM, Jonathan Vanasco <jonat...@findmeon.com> wrote: > >> I'm not sure if there is a trick to do this or not, but it's worth asking... >> >> I have an object that has been loaded into the Session, as per whatever >> eager-loading requirements : >> >> foo = dbSession.query( Foo ).filter(...).options(...).one() >> >> >> I'm now in a position where I need to access Foo.bar and Foo.bar.baz >> >> for bar in foo.bar : >> print foo.bar.baz.id >> >> >> Is there a way to eagerload foo.bar and foo.bar.baz into the already-loaded >> `foo` ? >> >> I'd prefer not to re-query for `foo` with different attributes, because it >> was loaded elsewhere with some specific needs. i just want to tell it to >> eagerload this collection/depth. >> >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to sqlalchemy+unsubscr...@googlegroups.com. >> To post to this group, send email to sqlalchemy@googlegroups.com. >> Visit this group at http://groups.google.com/group/sqlalchemy. >> For more options, visit https://groups.google.com/d/optout. > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.