Skip to content

Instantly share code, notes, and snippets.

@ornerymoose
Created December 4, 2017 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ornerymoose/72bf96ad2cfff54a3fb91c902036bf1d to your computer and use it in GitHub Desktop.
Save ornerymoose/72bf96ad2cfff54a3fb91c902036bf1d to your computer and use it in GitHub Desktop.
So this 'works', in a sense: it's doing the UPDATE but also doing an INSERT. Why is that? Screenshot of server log: https://imgur.com/a/8FCPN
class Relationship < ApplicationRecord
belongs_to :outage
belongs_to :child
validate :outage_changed, if: :outage_id_changed?
private
def outage_changed
Relationship.where(child_id: self.child_id).update_all(outage_id: self.outage_id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment