Вот модель:
sections=sa.Table('sections',meta.metadata,
sa.Column('id',sa.types.Integer,primary_key=True),
sa.Column('parent_id',sa.types.Integer, sa.ForeignKey('sections.id')),
sa.Column('name',sa.types.String(255)),
sa.Column('active',sa.types.Boolean),
)
class Sections(object):
def __repr__(self):
return self.name
orm.mapper(
Sections,sections,
properties={
'parent':orm.relation(
Sections,remote_side=[sections.c.id], backref=orm.backref('childrens')
)
},
)
articles=sa.Table('articles',meta.metadata,
sa.Column('id',sa.types.Integer,primary_key=True,autoincrement=True),
sa.Column('section_id',sa.types.Integer, sa.ForeignKey('sections.id')),
sa.Column('name',sa.types.String(255),default=u'',nullable=False),
sa.Column('active',sa.types.Boolean,default=0,nullable=False),
)
class Articles(object):
def __repr__(self):
return self.name
orm.mapper(
Articles,articles,
properties={'section':orm.relation(Sections,backref=orm.backref('articles'))},
)
Хочу получить одну запись, из которой потом буду получать сведения по внешнему ключу.
section=Session.query(model.Sections).get(id)
Как построить запрос, чтобы section.articles были только те, где active были только True?