当我在
Stack Level Too Deep Error
中调用vendor.account_owner 时,我得到
index.html.erb
供应商迁移文件如下所示
class CreateVendors < ActiveRecord::Migration[7.0]
def change
create_table :vendors, id: :uuid do |t|
t.string :name
t.text :description
t.string :website
t.references :account_owner, foreign_key: { to_table: :users }, type: :uuid
t.jsonb :data_classification, default: '{}', null: false
t.integer :auth_type, default: 0
t.integer :risk, default: 1
t.datetime :engagement_date
t.datetime :last_review_date
t.boolean :is_active, default: true
t.timestamps
end
end
end
供应商模型看起来像这样
class Vendor < ApplicationRecord
store_accessor :data_classification, :employee_data, :corporate_data, :customer_data, :personal_data, :healthcare_data, :payments_data
enum :auth_type, { Unknown: 0, SSO: 1, Password: 2 }
enum :risk, { Low: 0, Medium: 1, High: 2 }
belongs_to :account_owner, class_name: 'User', foreign_key: :author_id
has_many :documents, as: :documentable
def account_owner
account_owner.first_name
end
end
而用户模型看起来像这样
class User < ApplicationRecord
...
has_many :authored_policies, class_name: 'Policy', foreign_key: 'author_id'
has_many :created_groups, class_name: 'Group', foreign_key: 'creator_id'
has_many :vendors, foreign_key: 'account_owner_id'
def full_name
first_name + " " + last_name
end
end
我在平台上检查过类似的错误消息,但它没有解决这种特殊情况 我需要帮助,因为我相信我可能遗漏了一些东西
您的
Vendor
课程有这个:
def account_owner
account_owner.first_name
end
Stack Level Too Deep Error
,因为它永远不会终止。belongs_to :account_owner ...
关联。尝试给它起一个不同的名称,例如:
def account_owner_first_name
account_owner.first_name
end