Rails6.0由于无法识别外键而导致_many-belongs_to失败



我有两个模型Loan::Transaction和Loan:;Transaction::Transition。它们都在文件夹"中;模型";而内部";贷款";。第二个也是在文件夹"内;交易";。

1贷款::交易有许多贷款::事务::转换
1贷款::业务::转换属于1贷款:事务

Loan::Transaction::Transition的列为Loan_Transaction_id

迁移:

class CreateLoanTransactionTransitions < ActiveRecord::Migration[6.0]
def up
create_table :loan_transaction_transitions, id: :uuid do |t|
t.timestamps
t.references :loan_transaction, type: :uuid, null: false, index: true,
foreign_key: { to_table: :loan_transactions }
t.string :reason
t.references :made_by, type: :uuid, null: true, foreign_key: { to_table: :users }
end
add_column :loan_transaction_transitions, :from_status, :transaction_status, null: false
add_column :loan_transaction_transitions, :to_status,   :transaction_status, null: false
end
def down
drop_table :loan_transaction_transitions
end
end

过渡等级:

class Loan::Transaction::Transition < ApplicationRecord
validates :to_status, presence: true
validates :from_status, presence: true
validates :loan_transaction_id, presence: true
belongs_to :made_by, class_name: 'User', foreign_key: 'made_by_id', optional: true
belongs_to :loan_transaction, class_name: 'Loan::Transaction', foreign_key: 'loan_transaction_id', inverse_of: :transitions
end

交易类别:

class Loan::Transaction < ApplicationRecord
extend ActiveSupport::Concern

has_many :transitions, class_name: 'Transaction::Transition', dependent: :destroy, foreign_key: 'loan_transaction_id', inverse_of: 'loan_transaction'
accepts_nested_attributes_for :transitions
end

当我尝试做一些类似";贷款::交易。首先。过渡;我得到以下错误:ActiveRecord::StatementInvalid(PG::UndefinedColumn:ERROR:列loan_transaction_transactions.transaction_id不存在(第1行:。。。作为一个FROM";transaction_transitions";其中";loan_tran。。。

但我试图在很多方面具体说明这一点。到目前为止一切都不起作用。我为postrgreSQL使用dockercompose3.7,为web服务器使用另一个容器。

我设法"修复";通过改变迁移字段";贷款交易->quot;交易";和Transition类中的外键值。不理想的坚韧

相关内容

  • 没有找到相关文章

最新更新