has_and_belongs_to_many 和 foreign_key 在 Rails Admin + MongoID 中不起作用

has_and_belongs_to_many and foreign_key does not work in Rails Admin + MongoID

我正在使用 Rails 5,Rails Admin 和 MongoId,在我的模型中,我添加了

has_and_belongs_to_many :topics, class_name: 'Topic', :foreign_key => :topicIds 

它适用于 'edit page',但当我尝试更改 topicIds

的值时不起作用
message: Attempted to set a value for 'topic_ids' which is not allowed on the model AppUser. summary: Without including Mongoid::Attributes::Dynamic in your model and the attribute does not already exist in the attributes hash, attempting to call AppUser#topic_ids= for it is not allowed. This is also triggered by passing the attribute to any method that accepts an attributes hash, and is raised instead of getting a NoMethodError. resolution: You can include Mongoid::Attributes::Dynamic if you expect to be writing values for undefined fields often.

说明MongoId没有完全理解':foreign_key'。您有解决办法吗?

我通过向模型添加别名字段解决了我的问题:

field :topicIds, type: Array, :as => :topic_ids