[sqlalchemy] Re: Inferring joins from table A to table C via table B

2009-09-03 Thread Jae Kwon
you can explicitly create these many-to-many join relations and eager load them. users = session.query(User).options(eagerload(User.groups)).all() if you want to query for relations with a filter, AFAIK you need to define them as a separate relation. class User(...) groups =

[sqlalchemy] Re: declarative style many to many, possible fix

2009-09-02 Thread Jae Kwon
Thanks for looking. What happens when viewonly=False? I tried appending/popping from the list of related secondary objects but I didn't see any duplicate inserts/deletes. - Jae On Sep 2, 2009, at 8:16 AM, Michael Bayer wrote: secondary requires a Table object as its argument. it is

[sqlalchemy] Re: declarative style many to many, possible fix

2009-09-02 Thread Jae Kwon
if you create new entities on the secondary table, and also insert records in the relation() with the secondary, it will persist them separately. I see that now. I have found myself using this pattern, however, since relation + secondary can create more efficient joins than an eagerload

[sqlalchemy] declarative style many to many, possible fix

2009-09-01 Thread Jae Kwon
Is there a way to declaratively create many to many relationships where the 'secondary' parameter for the relationship is deferred ? I couldn't get this to work, e.g. class User(DeclarativeBase): id = Column(Integer, primary_key=True) name = Column(String(20)) groups =

[sqlalchemy] Re: eagerload polymorphic object's relations, single table inheritance

2009-08-29 Thread Jae Kwon
, Jae Kwon wrote: I've seen similar discussions here, but it's been a while so perhaps things have changed. class Foo(Base): __tablename__ = 'foo' type = Column(Integer) __mapper_args__ = {'polymorphic_on': type} ... class BarFoo(Foo): __mapper_args__ = {'polymorphic_identity': 1

[sqlalchemy] Re: eagerload polymorphic object's relations, single table inheritance

2009-08-29 Thread Jae Kwon
oops, it looks like the second form (session.query(Item).with_polymorphic([FooItem, BarItem]).options(eagerload(FooItem.foochild, BarItem.barchild))) works fine. should i go ahead and try to write test cases? - Jae On Aug 29, 2009, at 2:23 PM, Jae Kwon wrote: I looked at this further

[sqlalchemy] eagerload polymorphic object's relations, single table inheritance

2009-08-28 Thread Jae Kwon
I've seen similar discussions here, but it's been a while so perhaps things have changed. class Foo(Base): __tablename__ = 'foo' type = Column(Integer) __mapper_args__ = {'polymorphic_on': type} ... class BarFoo(Foo): __mapper_args__ = {'polymorphic_identity': 1} bar_id =