Skip to content

Instantly share code, notes, and snippets.

@universal
Created October 24, 2016 14:28
Show Gist options
  • Save universal/68dcefd5ab0bb12f0ce9321db97503d8 to your computer and use it in GitHub Desktop.
Save universal/68dcefd5ab0bb12f0ce9321db97503d8 to your computer and use it in GitHub Desktop.
class AdditionalDomain < AR::Base
belongs_to :report
belongs_to :domain
validates :report, presence: true
validates :domain, presence: true
end
class Domain < AR::Base
end
class Report < AR::Base
belongs_to :primary_domain, class_name: "Domain"
has_many :additional_domains
has_many :domains, through: :additional_domains
validates :primary_domain, presence: true # checks object is on the association, but also allows new records
validates :primary_domain_id, presence: true # checks numeric value is set, but this could be a non existing value
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment