module Logistics module Core class TruckTypeCntWeightRange < ApplicationRecord belongs_to :truck_type_assignment belongs_to :weight_range validates :truck_type_assignment_id, uniqueness: {scope: [:truck_type_assignment_id, :weight_range_id]} def weight_from if self.weight_range_id weight_range = WeightRange.find self.weight_range_id weight_range.weight_from else nil end end def weight_to if self.weight_range_id weight_range = WeightRange.find self.weight_range_id weight_range.weight_to else nil end end def container_size if self.truck_type_assignment_id truck_type_assignment = TruckTypeAssignment.find self.truck_type_assignment_id container_size = ContainerSize.find truck_type_assignment.container_size_id container_size.name else nil end end def truck_type if self.truck_type_assignment_id truck_type_assignment = TruckTypeAssignment.find self.truck_type_assignment_id truck_type_assignment.truck_type end end def self.fetch_all truck_type_assignment_id result = [] truck_type_cnt_weight_ranges = TruckTypeCntWeightRange.where("truck_type_assignment_id" => truck_type_assignment_id) truck_type_cnt_weight_ranges.each do |truck_type_cnt_weight_range| result.push({id: truck_type_cnt_weight_range.id, weight_from: truck_type_cnt_weight_range.weight_from, weight_to: truck_type_cnt_weight_range.weight_to, weight_range_id: truck_type_cnt_weight_range.weight_range_id, truck_type_assignment_id: truck_type_cnt_weight_range.truck_type_assignment_id, container_size: truck_type_cnt_weight_range.container_size, truck_type: truck_type_cnt_weight_range.truck_type }) end return result end end end end