Class: Category
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Category
- Includes:
- ErpTechSvcs::Utils::DefaultNestedSetMethods
- Defined in:
- app/models/category.rb
Class Method Summary collapse
-
.apply_filters(filters, statement = nil) ⇒ ActiveRecord::Relation
Filter records.
- .iid(internal_identifier) ⇒ Object
-
.scope_by_dba_organization(dba_organization) ⇒ ActiveRecord::Relation
(also: scope_by_dba)
scope by dba organization.
-
.scope_by_party(party, options = {}) ⇒ ActiveRecord::Relation
scope by party.
Instance Method Summary collapse
Class Method Details
.apply_filters(filters, statement = nil) ⇒ ActiveRecord::Relation
Filter records
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/category.rb', line 48 def apply_filters(filters, statement=nil) unless statement statement = self end # filter by parent if filters[:parent] if filters[:parent].is_integer? statement = statement.where(categories: {parent_id: filters[:parent]}) else statement = statement.where(categories: {parent_id: Category.iid(filters[:parent])}) end end # filter by query which will filter on description if filters[:query] statement = statement.where('description like ?', "%#{filters[:query].strip}%") end statement end |
.iid(internal_identifier) ⇒ Object
107 108 109 |
# File 'app/models/category.rb', line 107 def iid(internal_identifier) where("internal_identifier = ?", internal_identifier).first end |
.scope_by_dba_organization(dba_organization) ⇒ ActiveRecord::Relation Also known as: scope_by_dba
scope by dba organization
75 76 77 |
# File 'app/models/category.rb', line 75 def scope_by_dba_organization(dba_organization) scope_by_party(dba_organization, {role_types: 'dba_org'}) end |
.scope_by_party(party, options = {}) ⇒ ActiveRecord::Relation
scope by party
or an array of Party ids comma separated or an Array
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/models/category.rb', line 90 def scope_by_party(party, ={}) statement = joins(:entity_party_roles) .where(entity_party_roles: {party_id: party}).uniq if [:role_types] role_types = [:role_types] unless role_types.is_a? Array role_types = role_types.split(',') end statement = statement.joins(entity_party_roles: :role_type) .where(role_types: {internal_identifier: role_types}) end statement end |
Instance Method Details
#to_data_hash ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/category.rb', line 112 def to_data_hash to_hash( only: [ :id, :description, :internal_identifier, :created_at, :updated_at ], leaf: leaf? ) end |