2011-10-13 16:55:03 +01:00
|
|
|
class Relation < ActiveRecord::Base
|
|
|
|
belongs_to :target, :polymorphic => true
|
|
|
|
belongs_to :object, :polymorphic => true
|
2011-10-23 22:39:44 +01:00
|
|
|
|
2011-11-16 18:45:01 +00:00
|
|
|
#has_many :role_lines
|
|
|
|
#has_many :roles, :autosave => true, :through => :role_lines
|
2011-11-18 18:35:12 +00:00
|
|
|
|
2011-11-18 18:26:22 +00:00
|
|
|
ROLES = %w[read write admin]
|
2011-11-16 18:45:01 +00:00
|
|
|
validates :role, :inclusion => {:in => ROLES}
|
|
|
|
|
|
|
|
#bitmask :roles, :as => [:read, :update]
|
2011-10-23 22:39:44 +01:00
|
|
|
|
|
|
|
scope :by_object, lambda {|obj| {:conditions => ['object_id = ? AND object_type = ?', obj.id, obj.class.to_s]}}
|
|
|
|
scope :by_target, lambda {|tar| {:conditions => ['target_id = ? AND target_type = ?', tar.id, tar.class.to_s]}}
|
2011-10-13 16:55:03 +01:00
|
|
|
end
|