Ruby on rails Rails 6在Rolify中有许多错误

Ruby on rails Rails 6在Rolify中有许多错误,ruby-on-rails,ruby,activerecord,migration,rolify,Ruby On Rails,Ruby,Activerecord,Migration,Rolify,我刚刚从rails 4.2.1迁移到rails 6.0.3.1,我遇到了与@scverano相同的HasManyThroughOrderError问题,我已经尝试了本文中提到的所有解决方案。我的关联声明顺序正确,下面是我的模型的样子: class User < ActiveRecord::Base rolify :after_add => :handle_role_change_async # Associations has_many :users_rol

我刚刚从rails 4.2.1迁移到rails 6.0.3.1,我遇到了与@scverano相同的HasManyThroughOrderError问题,我已经尝试了本文中提到的所有解决方案。我的关联声明顺序正确,下面是我的模型的样子:

class User < ActiveRecord::Base
   rolify :after_add => :handle_role_change_async
   
   # Associations
   has_many :users_roles, dependent: :destroy
   has_many :roles, through: :users_roles
end
我正在使用: Ruby 2.5.8 轨道6.0.3.1 Rolif5.3.0

有人知道还发生了什么吗?我已经看了好几篇帖子,所有的孤寂都建议你先声明你要经历的联系,但这对我来说并不奏效


我将非常感谢您的帮助,谢谢您可以这样尝试。我想这应该对你有帮助

# app/models/user.rb

class User < ActiveRecord::Base
   rolify :after_add => :handle_role_change_async
   
   # Associations
   has_many :user_roles, dependent: :destroy
   has_many :roles, through: :user_roles
end

#app/models/user.rb
类用户:处理\u角色\u更改\u异步
#联想
有多个:用户角色,依赖::销毁
有多个:角色,通过::用户角色
结束
#app/models/role.rb
类角色
很抱歉,粘贴代码时出错,我刚刚编辑了我的帖子。最初我已经在使用类UserRoleclass UserRole < ActiveRecord::Base belongs_to :role belongs_to :user belongs_to :resource, polymorphic: true end
Started GET "/" for 172.25.0.1 at 2020-10-21 16:22:51 +0000
  User Load (3.3ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 16], ["LIMIT", 1]]
  ↳ app/lib/user_constraint.rb:3:in `matches?'
Processing by MapsController#index as HTML
Completed 500 Internal Server Error in 127ms (ActiveRecord: 0.0ms | Allocations: 5413)



ActiveRecord::HasManyThroughOrderError (Cannot have a has_many :through association 'User#roles' which goes through 'User#users_roles' before the through association is defined.):

app/user_profiling/user_modules.rb:27:in `load_modules'
app/user_profiling/user_modules.rb:16:in `initialize'
app/user_profiling/user_profiling.rb:22:in `new'
app/user_profiling/user_profiling.rb:22:in `initialize'
app/controllers/application_controller.rb:40:in `new'
app/controllers/application_controller.rb:40:in `load_profiling'
app/middleware/notifications_backend.rb:51:in `call!'
app/middleware/notifications_backend.rb:18:in `call'
# app/models/user.rb

class User < ActiveRecord::Base
   rolify :after_add => :handle_role_change_async
   
   # Associations
   has_many :user_roles, dependent: :destroy
   has_many :roles, through: :user_roles
end

# app/models/role.rb

class Role < ActiveRecord::Base
  # Associations
  has_many :user_roles, dependent: :destroy
  has_many :users, through: :user_roles
end