0
我有兩個模型,消息和用戶。消息有兩個用戶對象user_1和user_2。爲什麼#在Rails SQL語句中無法識別?
class Message < ActiveRecord::Base
attr_accessible :user_1, :user_2
belongs_to :user_1, :class_name => "User"
belongs_to :user_2, :class_name => "User"
end
class User < ActiveRecord::Base
attr_accessible :email, :password
has_many :message, dependent: :destroy, :finder_sql => 'SELECT * FROM messages where (user_1_id = #{id} or user_2_id = #{id})'
end
當我嘗試和刪除用戶對象,我得到以下錯誤:
ActiveRecord::StatementInvalid in UsersController#destroy
SQLite3::SQLException: unrecognized token: "#": SELECT * FROM messages where (user_1_id = #{id} or user_2_id = #{id})
該錯誤消息似乎很平淡,但我認爲#是正確的語法。我正在使用Rails 3.2.3。謝謝!