0
我有一個存儲user_ids及其會話的Session表。我需要找到當前登錄的會話表中的所有用戶,然後是用戶,如跟在Twitter中一樣,但不包括列表中的current_user id。這裏是我當前的代碼:Rails 4:如何在不同的表中找到不包含current_user id的user_id數組?
Session.where.not(:user_id => current_user).pluck(current_user.following.map(&:user_id))
感謝@riarcombe 。我得到'未定義的方法user_id'。就像我以前一樣,它在'Session.where(user_id:current_user.following.map(&:user_id))。where.not(user_id:current_user).pluck(:user_id)' –
OK。我通過回答編輯。我的猜測是current_user.following給你一個用戶集合...在這種情況下需要映射id。 – rlarcombe
太棒了,就是這樣!謝謝@rlarcombe!我很快就會向你提供信貸。 –