Last active
September 2, 2016 12:29
-
-
Save luciuschoi/4520e829a3135ff324bb315b3748b9cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 감사합니다...! | |
# 1. Club.all.select{|k| k.memberships.count < k.max_number} | |
# 2. club.unconfirmed_applications.map(&:user) | |
# 1에 해당하는 클럽들에 대해 2번을 적용한 유저정보(특히 user.phone_number)를 추출하려면 어떻게 해야 할까요? | |
class Club < ApplicationRecord | |
scope :recruiting, -> { select{ | club | club.memberships.count < club.max_number } } | |
scope :unconfirmed, -> { recruiting.unconfirmed_applications } | |
def unconfirmed_user_phones | |
@user = Club.unconfirmed.users | |
@user_phones = @user.pluck(:phone_number) # @user_phones는 전화번호 배열을 리턴합니다. | |
end | |
... | |
end | |
제가 잘 못 이해한 것이 있으면 알려 주세요. 전체 모델과 관계 정보가 없어서 매우 제한적인 상황에서 생각해 본 것입니다. | |
Club.all.select{|k| k.memberships.count < k.max_number}.map do |c| | |
c.unconfirmed_applications.map{ | application | "#{application.user.name} - #{application.user.phone_number}" } | |
end | |
Club.all.select{|k| k.memberships.count < k.max_number}.map do |c| | |
c.unconfirmed_applications.map{ | application | { name: application.user.name, phone_number: application.user.phone_number } } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment