1

我有 2 张桌子:

反馈 : faceid (as int), Poolid (as int), deleted (as boolean)

池:id(作为 int),取消(作为布尔值)

两个表之间没有数据库集成,除了某些行包含相同的值(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') 

实现它的最佳(和参数化)方法是什么?

4

2 回答 2

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]}")
于 2013-01-30T07:28:01.803 回答
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]})")

谢谢你们

于 2013-01-30T21:27:30.687 回答