如何修复有关self.reflect_on_all_associations的“调用Project.connection以建立连接”

时间:2019-04-28 17:24:35

标签: ruby-on-rails-5 rails-activestorage activesupport-concern

我已经使用ActiveStorage在Rails 5应用程序中处理附件,每个附件都需要某些方法。

为此,我在模型中编写了以下代码,并且该代码正在运行:

self.reflect_on_all_associations do |a|
    puts a.inspect
end

现在,我想在代码中添加此代码以在所有模型中使用,但是当我在代码中编写代码时,在运行rails c时会抛出此错误:

#<ActiveRecord::Reflection::HasManyReflection:0x007fcdda57f288 @name=:integration_logs, @scope=nil, @options={:as=>:loggable, :dependent=>:nullify}, @active_record=Project (call 'Project.connection' to establish a connection), @klass=nil, @plural_name="integration_logs", @type="loggable_type", @foreign_type=nil, @constructable=true, @association_scope_cache=#<Concurrent::Map:0x007fcdda57ef40 entries=0 default_proc=nil>>

这是我关心的代码:

module Storeable
  extend ActiveSupport::Concern

  included do
    self.reflect_on_all_associations.each do |a|
      puts a.inspect
    end
  end
end

这是我模型中的代码:

class Project < ApplicationRecord
  include Storeable
  has_one_attached :image, dependent: :destroy
  has_one_attached :bundle_file, dependent: :destroy
  has_one_attached :android_file, dependent: :destroy
  has_one_attached :ios_file, dependent: :destroy
end

0 个答案:

没有答案