1
roles = Role.find_all_by_simulation_id(session[:sim_id])
forum_posts = Post.find(:all, :conditions => ["role_id = ? AND created_at > ?", roles.map(&:id), session[:last_login]])

错误:

SQLite3::SQLException: near ",": syntax error: SELECT * FROM "posts" WHERE (role_id = 1,2,3,4 AND created_at > '2009-05-21 11:54:52') 
4

2 回答 2

2

改变这个:

forum_posts = Post.find(:all, :conditions => ["role_id = ? AND created_at > ?", roles.map(&:id), session[:last_login]])

forum_posts = Post.find(:all, :conditions => ["role_id IN (?) AND created_at > ?", roles.map(&:id), session[:last_login]])
于 2009-05-21T13:10:34.727 回答
1

我认为 Role_id = 1,2,3,4 中的逗号。我认为它需要 role_id='1,2,3,4' 如果它是一个字符串或 role_id IN (1,2,3,4) 如果你想对整数进行 OR 样式比较。

于 2009-05-21T12:52:56.883 回答