You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classCourse < ApplicationRecordhas_many:user_and_course_records,dependent: :destroyhas_many:course_times,dependent: :destroyhas_many:users,through: :user_and_course_recordsscope:mon,->{joins(:course_times).where("section LIKE ?","週一%").pluck(:name,:section)}scope:thus,->{joins(:course_times).where("section LIKE ?","週二%").pluck(:name,:section)}scope:wed,->{joins(:course_times).where("section LIKE ?","週三%").pluck(:name,:section)}scope:thur,->{joins(:course_times).where("section LIKE ?","週四%").pluck(:name,:section)}scope:fri,->{joins(:course_times).where("section LIKE ?","週五%").pluck(:name,:section)}scope:sat,->{joins(:course_times).where("section LIKE ?","週六%").pluck(:name,:section)}scope:sun,->{joins(:course_times).where("section LIKE ?","週日%").pluck(:name,:section)}end
重構 ORM 查詢規則
課表查詢能找出每週特定日期的所有課程
目前做法
由 course 進行查詢
重構後做法
由 course_time 進行查詢, ORM 應類似為下方程式碼
The text was updated successfully, but these errors were encountered: