Sha256: 22099ada2a8ed0ba0e697554266efc073b37f9c77e6068fa4330cfcc4ff1e43a

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module Alberich
  class Entity < ActiveRecord::Base
    attr_accessible :entity_target, :entity_target_id, :name

    belongs_to :entity_target, :polymorphic => true
    validates_presence_of :entity_target_id
    has_many :session_entities, :dependent => :destroy
    has_many :permissions, :dependent => :destroy
    has_many :derived_permissions, :dependent => :destroy

    # type-specific associations
    belongs_to :user, :class_name => Alberich.user_class, :foreign_key => "entity_target_id"
    belongs_to :user_group, :class_name => Alberich.user_group_class,
                            :foreign_key => "entity_target_id"

    def self.for_target(obj)
      self.find_by_entity_target_id_and_entity_target_type(obj.id,
                                                           obj.class.name)
    end

    def self.find_or_create_for_target(obj)
      self.find_or_create_by_entity_target_id_and_entity_target_type(obj.id,
                                                                 obj.class.name)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alberich-0.2.0 app/models/alberich/entity.rb