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 =
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
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
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 =
, 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
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
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 =