予約管理アプリのバージョンアップを行っています。
rails6へバージョンアップをして、動作を確認しておりましたところ特定の画面で、下記のエラーが発生しました。
ActionView::Template::Error (PG::UndefinedTable: ERROR: missing FROM-clause entry for table "company_groups" LINE 1: SELECT "companies".* FROM "companies" WHERE (company_groups.... ^ 4: .control-group 5: = f.label :company_id, :class => 'control-label' 6: .controls 7: = f.collection_select :company_id, Company.user_companies, :id, :name 8: .control-group 9: = f.label :service_unit_id, :class => 'control-label' 10: .controls app/views/admin/service_contracts/_form.html.haml:7 app/views/admin/service_contracts/_form.html.haml:2 app/views/admin/service_contracts/edit.html.haml:4
他の部分で同じエラーが出たのですが、それは下記の方法で修正しました。
Book.includes(calendar: :company).where("companies.id = ?", company).count ↓↓↓↓↓↓↓↓↓↓ Book.includes(calendar: :company).where("companies.id = ?", company).references(:companies).count
しかし、今回のエラーではどこを修正すればよいかわかりません。
どなたかご教授いただければ幸いです。
何卒宜しくお願い致します。
追記
company.rb
1class Company < ActiveRecord::Base 2 3 GIGA = 1024 * 1024 * 1024 4 5 default_scope { order("companies.id ASC") } 6 7 include SecurityEngine 8 9 validates_uniqueness_of :login_name 10 validates_numericality_of :storage_capacity_gb, 11 :greater_than_or_equal_to => :storage_size_needed_gb, 12 :on => :update 13 after_save :update_browsers 14 15 has_many :browsers, dependent: :destroy 16 has_many :drawers, dependent: :nullify 17 has_many :service_contracts, dependent: :destroy 18 has_many :service_units, through: :service_contracts 19 has_many :credits, class_name: "Charge", 20 foreign_key: :payee_id, dependent: :nullify 21 has_many :debts, class_name: "Charge", 22 foreign_key: :payer_id, dependent: :nullify 23 belongs_to :account_type 24 has_many :shops, :dependent => :destroy 25 has_many :customers, :dependent => :destroy 26 has_many :users, :dependent => :destroy 27 has_many :generations,->{ order(:position) } ,:dependent => :destroy 28 has_many :custom_links, ->{ order(:position) }, :dependent => :destroy 29 has_many :item_groups, ->{ order(:position) }, :dependent => :destroy 30 has_many :items, :dependent => :destroy 31 has_many :inventories, :dependent => :destroy 32 has_many :deals, :dependent => :destroy 33 has_many :sales, :dependent => :destroy 34 has_many :occupations, :dependent => :destroy 35 belongs_to :number_factory 36 belongs_to :ymd_input_style 37 has_many :custom_fields, :dependent => :destroy 38 has_many :custom_field_items, :dependent => :destroy 39 has_many :photos, :dependent => :destroy 40 has_many :payment_types, :dependent => :destroy 41 has_many :payments, :dependent => :destroy 42 has_many :trend_cubes, :dependent => :destroy 43 has_many :cubes, :dependent => :destroy 44 has_many :stocks, :dependent => :destroy 45 has_many :calendars, ->{ order(:position) }, :dependent => :destroy 46 belongs_to :company_group 47 belongs_to :manager, class_name: "User" 48 belongs_to :sales_company, class_name: "Company" 49 belongs_to :sales_person, class_name: "User" 50 has_many :user_notifications, dependent: :nullify 51 has_many :customer_notifications, dependent: :nullify 52 53 before_save :encrypt_privacy_information 54 after_save :decrypt_privacy_information 55 after_find :decrypt_privacy_information 56 57 scope :managed_by_dealer, lambda { 58 includes(:company_group). 59 where("company_groups.has_grant_sale = ? OR company_groups.has_grant_use = ? OR company_groups.has_grant_billing = ?", true, true, true) 60 } 61 62 scope :providers, lambda { 63 includes(:company_group). 64 where("company_groups.has_grant_maintenance = ?", true) 65 } 66 67 scope :dealers, lambda { 68 includes(:company_group). 69 where("company_groups.has_grant_service = ?", true) 70 } 71 72 scope :user_companies, lambda { 73 includes(:company_group). 74 where("company_groups.has_grant_use = ?", true) 75 } 76 77 scope :actives_on, lambda { |date = Date.today| 78 where("companies.end_at is null OR companies.end_at > ?", date) 79 } 80 81 def has_multi_shops? 82 self.shops.count > 1 83 end 84 85 def first_sale 86 self.sales.count > 0 ? self.sales.order("ordered_at ASC").first : nil 87 end 88 89 def sold(from = Date.today, to = Date.today) 90 self.sales.during(from, to).sum(:final_price) 91 end 92 93 def paid(from = Date.today, to = Date.today) 94 self.payments.actives.during(from, to).sum(:price) 95 end 96 97 def customers_at(d = Date.today) 98 self.customers.where("start_at <= ?", d).order("start_at ASC") 99 end 100 101 def accounts_receivable(from = self.first_sale.ordered_at, to = Date.today) 102 self.sold(from, to) - self.paid(from, to) 103 end 104 105 def storage_used 106 self.photos.sum(:image_file_size) 107 end 108 109 def storage_size_needed_gb 110 gb_needed = (1.0 * self.storage_used / GIGA).ceil 111 [12, gb_needed].max 112 end 113 114 def storage_free_space 115 self.storage_capacity_gb * GIGA - self.storage_used 116 end 117 118 def storage_used_percentage 119 100 * self.storage_used / (self.storage_capacity_gb * GIGA) 120 end 121 122 def customers_with_large_debts(n = 10) 123 self.customers.except(:order).order("accounts_receivable DESC").limit(n) 124 end 125 126 def ready? 127 status = true 128 129 status = status && (self.item_groups.count > 0) 130 status = status && (self.items.count > 0) 131 status = status && (self.payment_types.count > 0) 132 status = status && (self.occupations.count > 0) 133 status = status && (self.shops.count > 0) 134 135 return status 136 end 137 138 def root_item_groups 139 self.item_groups.roots.actives 140 end 141 142 def leaf_item_groups 143 leafs = [] 144 self.item_groups.actives.each do |ig| 145 leafs << ig if ig.leaf? 146 end 147 148 return leafs 149 end 150 151 def is_system_provider? 152 self.company_group && self.company_group.has_grant_maintenance 153 end 154 155 def is_dealer? 156 self.company_group && self.company_group.has_grant_service 157 end 158 159 def is_user? 160 self.company_group && self.company_group.has_grant_use 161 end 162 163 def credit_amount 164 self.credits.not_paid.sum(:amount) 165 end 166 167 def debt_amount 168 self.debts.not_paid.sum(:amount) 169 end 170 171 def has_credits? 172 self.credits.not_paid.count > 0 173 end 174 175 def has_debts? 176 self.debts.not_paid.count > 0 177 end 178 179 def get_contract(service_unit) 180 return nil if service_unit.nil? 181 return self.service_contracts.where(service_unit_id: service_unit.id).first 182 end 183 184 def activate_service(service_unit, user) 185 service_contract = get_contract(service_unit) 186 187 if service_contract.nil? && service_unit 188 service_contract = self.service_contracts.new(service_unit_id: service_unit.id) 189 end 190 191 return false if service_contract.nil? 192 193 return service_contract.activate(user) 194 end 195 196 def deactivate_service(service_unit, user) 197 service_contract = get_contract(service_unit) 198 199 return false if service_contract.nil? 200 return service_contract.deactivate(user) 201 end 202 203 def using?(service_unit) 204 service_contract = get_contract(service_unit) 205 return service_contract ? service_contract.active : false 206 end 207 208 def monthly_charge 209 self.service_contracts.actives.sum(:price) 210 end 211 212 def basic_contract 213 self.service_contracts.actives.each do |sc| 214 return sc if sc.service_unit.mandatory 215 end 216 return nil 217 end 218 219 def option_service_units 220 return self.basic_contract.service_unit.option_service_units 221 end 222 223 def has_bank_info? 224 return false if self.bank_name.blank? 225 return false if self.bank_branch.blank? 226 return false unless self.account_type 227 return false unless self.account_number 228 return !self.account_name.blank? 229 end 230 231 def num_of_books_without_sale 232 return self.calendars.inject(0) do |num_books, calendar| 233 num_books += calendar.books.without_sale.count 234 end 235 end 236 237 def num_of_books_in_today 238 return self.calendars.inject(0) do |num_books, calendar| 239 num_books += calendar.books.of_day(Date.today).count 240 end 241 end 242 243 def has_drawer? 244 self.drawers.count > 0 245 end 246 247 def is_using?(service_unit_name_tag) 248 if self.service_units.with_name_tag(service_unit_name_tag).count > 0 249 return true 250 end 251 252 ServiceUnit.with_name_tag(service_unit_name_tag).each do |su| 253 self.service_units.each do |s| 254 return true if s.includes?(su) 255 end 256 end 257 258 return false 259 end 260 261 def pusher_channel 262 return "Company-%d" % self.id 263 end 264 265 def active? 266 return true if self.end_at.nil? 267 return self.end_at > Date.today 268 end 269 270 private 271 def encrypt_privacy_information 272 self.bank_name = encrypt(self.bank_name) 273 self.bank_branch = encrypt(self.bank_branch) 274 self.account_number = encrypt(self.account_number) 275 self.account_name = encrypt(self.account_name) 276 end 277 278 def decrypt_privacy_information 279 self.bank_name = decrypt(self.bank_name) 280 self.bank_branch = decrypt(self.bank_branch) 281 self.account_number = decrypt(self.account_number) 282 self.account_name = decrypt(self.account_name) 283 end 284 285 def update_browsers 286 unless self.manage_browser 287 self.browsers.each do |b| 288 b.logout 289 end 290 end 291 end 292end 293
回答1件
あなたの回答
tips
プレビュー