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

在这里疯狂猜测:

在 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 回答
0

认为这是连接,看来您正在将 Post 加入 PostOptions 上 PostOption.post_id = 一些文字值。认为你的意思是这样的:

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 回答