MongoMapper 中的键名称冲突

发布于 2024-11-06 09:41:37 字数 477 浏览 0 评论 0原文

我在 sinatra 服务中使用 mongo mapper (0.8.6)。我有一个问题,堆栈级别太深。问题是我的模型中的关键“changes”存在冲突。这是我的模型:

class ChangeLog
  include MongoMapper::Document

  belongs_to :resource

  key :changes, Hash, :required => true
  key :message, String, :required => true
  key :note, String
  key :user_uuid, String, :required => true
  key :user_name, String, :required => true
  timestamps!
end

但是,我不想重命名我的密钥,因为在本例中,它是我的 Web 服务的正确名称。有什么建议吗?

I use mongo mapper (0.8.6) in my sinatra service. I have one problem with stack level too deep. The problem is that there is conflict of the key "changes" in my model. Here is my model:

class ChangeLog
  include MongoMapper::Document

  belongs_to :resource

  key :changes, Hash, :required => true
  key :message, String, :required => true
  key :note, String
  key :user_uuid, String, :required => true
  key :user_name, String, :required => true
  timestamps!
end

However, I don't want to rename my key as in this case, it's the right name for my web service. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朱染 2024-11-13 09:41:37

changes 是一个实例方法,它会告诉您自上次保存文档以来哪些字段发生了更改。这是 MongoMapper 文档 中的示例

user = User.create(:name => 'John', :age => 29)

puts user.changed?        # false
puts user.changes.inspect # {}

user.name = 'Steve'
puts user.changed?            # true
puts user.changes.inspect     # {"name"=>["John", "Steve"]}

不幸的是,您可能需要选择不同的该字段的名称。也许是“调整”或“变化”或“差异”或“修改”?

changes is an instance method that will tell you what fields have changed since you last saved the document. Here's an example from MongoMapper's documentation

user = User.create(:name => 'John', :age => 29)

puts user.changed?        # false
puts user.changes.inspect # {}

user.name = 'Steve'
puts user.changed?            # true
puts user.changes.inspect     # {"name"=>["John", "Steve"]}

Unfortunately, you're probably going to need to choose a different name for that field. Maybe "adjustments" or "variations" or "differences" or "modifications"?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文