0
    posts_query = (db.session.query(Post).
                   join(PostOption,PostOption.post_id == post_obj.id).
                   filter(and_(PostOption.key == "name",
                               PostOption.val == 'a')).
                   filter(Post.place_id == post_obj.place_id)
                   )

    print map(lambda x:get_post_values(x),posts_query.all())

戻り値

[{u'name': u'a'}, {u'name': u'a'}, {u'name': u'a'}, {u'name': u'a'}, {u'name': u'a'}, {u'name': u'a'}, {u'name': u'a'}, {u'name': u'a'}, {u'name': u'a'}, {u'name': u'a'}, {u'name': u'a'}, {u'name': u'a'}, {u'name': u'a'}, {u'name': u'a'}, {u'name': u'b'}, {u'name': u'b'}, {u'name': u'b'}, {u'name': u'b'}, {u'name': u'b'}, {u'name': u'b'}, {u'name': u'b'}, {u'name': u'b'}, {u'name': u'b'}, {u'name': u'b'}, {u'name': u'b'}, {u'name': u'b'}, {u'name': u'b'}]
4

2 に答える 2

0

これが結合だと考えてください。PostOption.post_id=リテラル値でPosttoPostOptionsに結合しているようです。あなたはこのようなことを意味すると思います:

posts_query = (db.session.query(Post).
  join(PostOption, PostOption.post_id == Post.id).
  filter(and_(PostOption.key == "name", PostOption.val == 'a')).
  filter(Post.place_id == post_obj.place_id).
  filter(Post.id == post_obj.id)
)
于 2012-08-16T18:17:38.017 に答える
0

ここでワイルドな推測:

and_内にplace_id句を含めます。

posts_query = (db.session.query(Post).
           join(PostOption,PostOption.post_id == post_obj.id).
           filter(and_(PostOption.key == "name",
                       PostOption.val == 'a',
                       Post.place_id == post_obj.place_id))
           )
于 2012-08-15T21:12:40.657 に答える