-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assign observers from observation report #477
Conversation
Mmm... interesting... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -25,17 +25,27 @@ class ObservationReport < ApplicationRecord | |||
# API creating report fails as it's not providing user. Thing to investigate | |||
belongs_to :user, inverse_of: :observation_reports, optional: true | |||
has_many :observation_report_observers, dependent: :destroy | |||
has_many :observers, through: :observation_report_observers | |||
has_many :observers, through: :observation_report_observers, after_add: :self_touch, after_remove: :self_touch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmmm.. I didn't know after_add
and after_remove
existed.
Cool!
touch unless destroyed? || new_record? | ||
end | ||
|
||
def sync_observation_observers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing in the future this won't be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
spec/factories/observations.rb
Outdated
@@ -86,10 +47,10 @@ | |||
severity { build(:severity, subcategory: subcategory) } | |||
operator { create(:operator, country: country) } | |||
observation_type { "operator" } | |||
observers { build_list(:observer, 1) } | |||
species { build_list(:species, 1, name: "Species #{Faker::Lorem.sentence}") } | |||
# species { build_list(:species, 1, name: "Species #{Faker::Lorem.sentence}") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm.. I think we can remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I forgot.
spec/factories/observations.rb
Outdated
severity | ||
country | ||
governments { build_list(:government, 2) } | ||
# species { build_list(:species, 1, name: "Species #{Faker::Lorem.sentence}") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Observation without report is only possible in "Created" state, which I would say should be named as "Draft" lol. In fact, we are missing all those required fields validations in the backend. |
dc17fa8
to
74673d0
Compare
…rvations having the same report
74673d0
to
f6858c4
Compare
1cfb9cf
to
78f83e3
Compare
Observation report should be the main source of observers for the observation.
Main changes:
We can keep the existing observation-observers relation for now, as changing this (removing that connection) could take a way more time. Changing API, and both applications to not seek observers in observation model but in observation report.