gpt4 book ai didi

ruby-on-rails - 如何在Rails Active Record查找和.map中使用SQL “IN”语句

转载 作者:行者123 更新时间:2023-12-03 08:05:45 27 4
gpt4 key购买 nike

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') 

最佳答案

改变这个:

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]])

关于ruby-on-rails - 如何在Rails Active Record查找和.map中使用SQL “IN”语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/892777/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com