|
4 | 4 | #
|
5 | 5 | # Table name: attendance_records
|
6 | 6 | #
|
7 |
| -# id :bigint not null, primary key |
8 |
| -# attending :boolean not null |
9 |
| -# created_at :datetime not null |
10 |
| -# updated_at :datetime not null |
11 |
| -# patient_id :bigint not null |
12 |
| -# session_date_id :bigint not null |
| 7 | +# id :bigint not null, primary key |
| 8 | +# attending :boolean not null |
| 9 | +# date :date not null |
| 10 | +# created_at :datetime not null |
| 11 | +# updated_at :datetime not null |
| 12 | +# location_id :bigint not null |
| 13 | +# patient_id :bigint not null |
13 | 14 | #
|
14 | 15 | # Indexes
|
15 | 16 | #
|
16 |
| -# index_attendance_records_on_patient_id (patient_id) |
17 |
| -# index_attendance_records_on_patient_id_and_session_date_id (patient_id,session_date_id) UNIQUE |
18 |
| -# index_attendance_records_on_session_date_id (session_date_id) |
| 17 | +# idx_on_patient_id_location_id_date_e5912f40c4 (patient_id,location_id,date) UNIQUE |
| 18 | +# index_attendance_records_on_location_id (location_id) |
| 19 | +# index_attendance_records_on_patient_id (patient_id) |
19 | 20 | #
|
20 | 21 | # Foreign Keys
|
21 | 22 | #
|
| 23 | +# fk_rails_... (location_id => locations.id) |
22 | 24 | # fk_rails_... (patient_id => patients.id)
|
23 |
| -# fk_rails_... (session_date_id => session_dates.id) |
24 | 25 | #
|
25 | 26 | class AttendanceRecord < ApplicationRecord
|
26 | 27 | audited associated_with: :patient
|
27 | 28 |
|
28 | 29 | belongs_to :patient
|
29 |
| - belongs_to :session_date |
| 30 | + belongs_to :location |
30 | 31 |
|
31 |
| - has_one :session, through: :session_date |
32 |
| - has_one :location, through: :session |
| 32 | + scope :today, -> { where(date: Date.current) } |
33 | 33 |
|
34 |
| - scope :today, -> { joins(:session_date).merge(SessionDate.today) } |
| 34 | + delegate :today?, to: :date |
35 | 35 |
|
36 |
| - delegate :today?, to: :session_date |
| 36 | + # This is needed to be able to pass a session to the policy. |
| 37 | + attr_accessor :session |
37 | 38 | end
|
0 commit comments