Sha256: 56414aef1511affbe819710d23e7a48c6d7942c1e242bcfb15901c33ab977687

Contents?: true

Size: 1008 Bytes

Versions: 8

Compression:

Stored size: 1008 Bytes

Contents

require 'action_view/helpers/auto_tag_helper/form_info'
require 'activerecord/mlang'
class OrgBranch < ActiveRecord::Base
  belongs_to :org
  belongs_to :org_branch_type
  has_many :branch_member_mappings, class_name: "OrgBranchMemberMapping"
  has_many :members, through: :branch_member_mappings, source: :org_member

  scope :has_member, ->(){ all.joins(branch_member_mappings: :org_member).uniq }

  include ActiveRecord::Mlang
  include ActionView::Helpers::AutoTagHelper::FormInfo
  set_accessible_attrs :org_branch_type_id, :position
  default_scope ->(){ order :position, :id }

  def __display__
    self.text.name.to_s + " " + self.org_branch_type.__display__
  end

  # @member : OrgMember
  def add(member)
    member_id = case member
                when Integer   then member
                when OrgMember then member.id
                else                member.to_i
                end
    OrgBranchMemberMapping.find_or_create_by(org_member_id: member_id, org_branch_id: self.id)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
we_bridge_rails_engine_orgs-0.1.16 app/models/org_branch.rb
we_bridge_rails_engine_orgs-0.1.15 app/models/org_branch.rb
we_bridge_rails_engine_orgs-0.1.14 app/models/org_branch.rb
we_bridge_rails_engine_orgs-0.1.13 app/models/org_branch.rb
we_bridge_rails_engine_orgs-0.1.12 app/models/org_branch.rb
we_bridge_rails_engine_orgs-0.1.11 app/models/org_branch.rb
we_bridge_rails_engine_orgs-0.1.10 app/models/org_branch.rb
we_bridge_rails_engine_orgs-0.1.9 app/models/org_branch.rb