Sha256: eb80a2a7521d1ccc8b6ce11ec827eaf43147452bf5289b689b0e5dd0dc407c2f

Contents?: true

Size: 709 Bytes

Versions: 7

Compression:

Stored size: 709 Bytes

Contents

module EveApp::ActivityRelation
  extend ActiveSupport::Concern

  included do
    belongs_to :type
    belongs_to :activity

    # scope :invention, -> { where(activity_id: EveApp::Activity::INVENTION) }
    scope :for, -> (tid, aid) { where(type_id: tid, activity_id: aid) }
    scope :order_by_name, -> {
      includes(type_name).order('types.name')
    }

    # ????
    # def activity_activity
    #   EveApp::Activity.where(type_id: type_id, activity_id: activity_id)
    # end
  end

  class_methods do
    def type_name
      reflections = self.reflect_on_all_associations(:belongs_to)
      reflections.select { |r| r.options[:class_name] == 'Type' && r.name != :type }.first.name
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
eve_app-0.1.6 app/models/concerns/eve_app/activity_relation.rb
eve_app-0.1.5 app/models/concerns/eve_app/activity_relation.rb
eve_app-0.1.4 app/models/concerns/eve_app/activity_relation.rb
eve_app-0.1.3 app/models/concerns/eve_app/activity_relation.rb
eve_app-0.1.2 app/models/concerns/eve_app/activity_relation.rb
eve_app-0.1.1 app/models/concerns/eve_app/activity_relation.rb
eve_app-0.1.0 app/models/eve_app/concerns/activity_relation.rb