0
我創建Rails中一個郵件系統,並且爲了顯示交談夥伴選擇屬性,我從CURRENT_USER包含在消息得到他們的ID ,因爲我需要只其他用戶從該查詢ID,我需要選擇它,我想選擇使用:to_id
或:user_id
取其不等於current_user.id
未current_user.id
喜歡的東西:
Message.where("to_id = ? or user_id = ?", current_user.id, current_user.id).select(:to_id, :user_id unless current_user.id)
預先感謝您!
編輯:這是信息表簡化爲:
create_table "messages", force: true do |t|
t.integer "to_id" -> User to whom the message was forwarded to
t.integer "user_id" -> User who wrote the message
end
是你只是想獲得一個ID數組,或者你需要知道它們是否來自:to_id和:user_id字段? – blotto