我有两张桌子:
反馈:faceid(作为int),Poolid(作为int),删除(作为布尔值)
Pool:id(as int),cancelled(as boolean)
两个表之间没有DB集成,除了事实上有些行包含相同的值(pool.id可以等于feedback.poolid)。
如果我在SQL中编写查询的地方,那就像是:
SELECT Pool.* , Feedback.* FROM Pool, Feedback WHERE faceid = params[:faceid]
and deleted = 'f' and (Pool.id = Feedback.poolid and Pool.cancel = 'f')
实现它的最佳(和参数化)方法是什么?
答案 0 :(得分:3)
我认为以下内容可行:
Pool.find_by_sql("select * from pools,feedbacks where pools.id = feedbacks.pool_id and cancelled = false and deleted = false and faceid = #{params[:faceid]}")
答案 1 :(得分:0)
@host = Pool.find_by_sql("SELECT pools.* FROM pools, feedbacks WHERE (pools.id = feedbacks.poolid) AND (pools.cancel = 'f') AND (feedbacks.deleted = 'f') AND (feedbacks.faceid = #{params[:faceid]})")
谢谢大家