On 11/30/2015 07:36 AM, Leily Zafari wrote: > I have two tables "Factorys" and "Products", each "Factory" can have a > large collection of "Products". For appends and filters the dynamic > loading method has been applied. > > | > | > |classFactory(Base): > > __tablename__ ='factorys' > ID =Column(Integer,primary_key=True) > products =relationship("Product",lazy='dynamic') > > > classProduct(Base): > > __tablename__ ='products' > ID =Column(Integer,primary_key=True) > factory_id =Column(Integer,ForeignKey('factorys.ID')) > Name=Column(Text) > > > > > | > But to have access to all "Products" of a "Factory", it is more > performant to have an eagerjoined loading between Factory and Product. > Is it possible to define different relations between two tables, but > using them only in specific cases? For example in a method for the > "Factory" class such as: > > |classFactory(Base):__tablename__ ='factorys'ID > =Column(Integer,primary_key=True)products > =relationship("Product",lazy='dynamic')def_getProducts():returnrelationship("Product",lazy='joined')| > > > How can I get all the "Products" of a "Factory" in a performant way, not > loosing performance when adding them to a "Factory"? > Any tips would be appreciated
you can build two separate relationships with a different strategy, just give them two separate names, like products_query vs. products > > -- > 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 > <mailto:sqlalchemy+unsubscr...@googlegroups.com>. > To post to this group, send email to sqlalchemy@googlegroups.com > <mailto: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.