noesya/osuny

View on GitHub
app/models/university/person/with_realm_communication.rb

Summary

Maintainability
A
0 mins
Test Coverage
C
72%
module University::Person::WithRealmCommunication
  extend ActiveSupport::Concern

  included do
    has_many  :communication_website_posts,
              class_name: 'Communication::Website::Post',
              foreign_key: :author_id,
              dependent: :nullify

    has_many  :author_websites,
              -> { distinct },
              through: :communication_website_posts,
              source: :website

    has_many  :communication_extranet_posts,
              class_name: 'Communication::Extranet::Post',
              foreign_key: :author_id,
              dependent: :nullify

    has_many  :author_extranets,
              -> { distinct },
              through: :communication_extranet_posts,
              source: :extranet
  end

  def posts
    communication_website_posts + communication_extranet_posts
  end
end