ubicloud/model/assigned_vm_address.rb
Enes Cakir 745bdf6e31 Fix vm association in AssignedVmAddress
The current configuration of the `vm` association in the
`AssignedVmAddress` is incorrect, leading to the below exception. This
issue arises because the `key` parameter corresponds to the column name
in the `Vm` table, while the `primary_key` refers to the column name in
the `AssignedVmAddress` table.

    [12] clover-development(main)> AssignedVmAddress.first.vm
    Sequel::DatabaseError: PG::UndefinedColumn: ERROR:  column vm.assigned_vm_address_id does not exist
    LINE 1: SELECT * FROM "vm" WHERE ("vm"."assigned_vm_address_id" = $1...
                                      ^
    from /Users/enescakir/.asdf/installs/ruby/3.2.4/lib/ruby/gems/3.2.0/gems/sequel-5.81.0/lib/sequel/adapters/postgres.rb:171:in `exec_params'
    Caused by PG::UndefinedColumn: ERROR:  column vm.assigned_vm_address_id does not exist
    LINE 1: SELECT * FROM "vm" WHERE ("vm"."assigned_vm_address_id" = $1...
                                      ^
    from /Users/enescakir/.asdf/installs/ruby/3.2.4/lib/ruby/gems/3.2.0/gems/sequel-5.81.0/lib/sequel/adapters/postgres.rb:171:in `exec_params'
2024-07-25 11:46:56 +03:00

11 lines
324 B
Ruby

# frozen_string_literal: true
require_relative "../model"
class AssignedVmAddress < Sequel::Model
one_to_one :vm, key: :id, primary_key: :dst_vm_id
many_to_one :address, key: :address_id
one_to_one :active_billing_record, class: :BillingRecord, key: :resource_id do |ds| ds.active end
include ResourceMethods
end