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'}]
答案 0 :(得分: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))
)
答案 1 :(得分:0)
认为这是加入,看来你在PostOption上加入Post to PostOptions.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)
)