Class: HhPackage::PackageGroup
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- HhPackage::PackageGroup
- Defined in:
- app/models/hh_package/package_group.rb
Overview
Schema Information
Table name: hh_package_package_groups
id :bigint not null, primary key
active :boolean default(TRUE)
name :string(255)
package_type :string(191) default("")
created_at :datetime not null
updated_at :datetime not null
hh_package_package_group_id :bigint not null
Constant Summary collapse
- PACKAGE_TYPE_MAPPING =
TODO need to remove this after all package type is migrated
{ 'ayce' => HhPackage::Package::Ayce, 'hah' => HhPackage::Package::HungryAtHome, 'pp' => HhPackage::Package::PartyPack, 'xp' => HhPackage::Package::Xperience, 'bfp' => HhPackage::Package::BuffetExtra, 'hs' => HhPackage::Package::HungrySet, 'sm' => HhPackage::Package::SetMenu, }.freeze
Instance Method Summary collapse
Methods inherited from ApplicationRecord
Instance Method Details
#packages ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/hh_package/package_group.rb', line 40 def packages # Fetch package attributes (id and type) for the current package group package_attrs = HhPackage::PackageAttr.where(package_group_id: id).pluck(:package_id, :package_type) # Initialize an empty array to collect packages packages = [] # Iterate over each package_id and package_type pair package_attrs.each do |package_id, package_type| # Find the corresponding class for the package_type klass = PACKAGE_TYPE_MAPPING[package_type.demodulize.underscore] # Query the correct class with the package_id if the class exists packages << klass.find_by(id: package_id) if klass end # Return the collected packages, excluding nil values packages.compact end |