我正在使用 Rails 3 和 mongoid。
我想根据另一条记录中的值保存或更新一条记录中的值。
例如:
class User
  include Mongoid::Document
  field :account_level, :type => Integer
end
class Profile
  include Mongoid::Document
  field :position, :type => Integer
end
如果account_levelin User 为 1,则positionin Profile 也应更新为 1。如果account_level is 2, then位置`应该是2。
这应该以编程方式完成,无需用户输入或在客户端使用不可见的输入字段(必须有比这更好的方法)。
额外的问题......我有以下逻辑(对于position),我该怎么做?
account_level1 = position1 
account_level2 = position1 
account_level3 = position5