계정이 있고 사용자 계정이 has_one 인 사용자 모델이 있습니다. 그래서 내 사용자 테이블에 account_id가 있습니다.계정에 사용자가있는 레일스 범위
나는 has_user = TUE/FALSE를 전달할 수있는 계정에 대한 범위를 만들고 사용자가 있거나없는 계정을 반환합니다.
scope :has_user, -> (has_user) { where(...) }
누구든지이 범위를 작성하는 방법을 도울 수 있습니까?
class Account < ApplicationRecord
has_one :user
scope :has_user, -> { includes(:user).where.not(users: { account_id: nil }) }
scope :has_not_user, -> { includes(:user).where(users: { account_id: nil }) }
end
다른 방법 :