Not doing so has a few gotchas when working with relations, particularly with records which are not stored in the database. I'm excluding the related content file because it's got a very peculiar relationship with itself: the `has_one :opposite_related_content` has no inverse; the relation itself is its inverse. It's a false positive since the inverse condition is true: ``` content.opposite_related_content.opposite_related_content.object_id == content.object_id ```
22 lines
495 B
Ruby
22 lines
495 B
Ruby
module Milestoneable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
has_many :milestones, as: :milestoneable, inverse_of: :milestoneable, dependent: :destroy
|
|
|
|
scope :with_milestones, -> { joins(:milestones).distinct }
|
|
|
|
has_many :progress_bars, as: :progressable, inverse_of: :progressable
|
|
|
|
acts_as_taggable_on :milestone_tags
|
|
|
|
def primary_progress_bar
|
|
progress_bars.primary.first
|
|
end
|
|
|
|
def secondary_progress_bars
|
|
progress_bars.secondary
|
|
end
|
|
end
|
|
end
|