Skip to content

Instantly share code, notes, and snippets.

@stevepolitodesign
Last active January 19, 2022 10:44
Show Gist options
  • Save stevepolitodesign/ca7e4b41f1d3a8560c9d7f72e7c4b353 to your computer and use it in GitHub Desktop.
Save stevepolitodesign/ca7e4b41f1d3a8560c9d7f72e7c4b353 to your computer and use it in GitHub Desktop.
Association extensions Example

Association Extensions

An API for adding new finders, creators, and other factory-type methods that are only used as part of this association.

class AnonymousSession < ApplicationRecord
  has_many :webpages, as: :owner do
    def nullify_owners
      # records returns an array of webpages
      records.each(&:nullify_owner)
    end
  end
end
class Webpage < ApplicationRecord
  def nullify_owner
    ...
  end
end
AnonymousSession.last.webpages.nullify_owners
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment