????????????????????????????????????????????????query refactor??model?????
????????????????????????????Щ????μ??Щ??????Щ???????????????????????
????????????model??user_assignments_query.rb
???????????class??????????????????
????class UserAssignmentsQuery
????def initialize(user)
????@user = user
????end
????end
?????????????????д?????????????????????select??joins????д?????????
????def call
????user
????.assignments.
????.select(select)
????.joins(join)
????.order("due_on DESC")
????end
????rails?????е???????????????????????д?????sql?????????????????select?? joins????????????order???????????????????? ?????? ??
??????????????????????????
????def join
????xxxxx
????end
????def select
????xxxxx
????end
??????????????????user??????????????
????attr_reader :user
???????attr_accessor??attr_reader??attr_writer ???????????????????????????????????????????????д???????????????????????????д??
????????????????????????????assignment??controller???÷?????:
????@assignments = DueAssignmentsQuery.new(current_user).call
??????????????????????????????????assignments????
????????????????user????????????????????????????????????????????γ???γ??????????????user???????????????????е?query model?????????γ????
?????????
????class UserAssignmentsQuery
????def initialize(user??course)
????@user = user
????@course = course
????end
????end
??????call??????м???where??????
????def call
????user
????.assignments.where(course_id: course.id )
????.select(select)
????.joins(join)
????.order("due_on DESC")
????end
???????????
????attr_reader :course
??????controller???????????
????@assignments = DueAssignmentsQuery.new(current_user?? course).call
??????? ?????joins??select????????????????Arel??SQL AST??????????????ο?????
??????????????????£?
????def assignments
????Assignment.arel_table
????end