【问题标题】:Finding Unassociated Records in Rails 3 with Mongoid?使用 Mongoid 在 Rails 3 中查找不相关的记录?
【发布时间】:2011-04-03 23:27:22
【问题描述】:

我的问题类似于this one,除了我试图在 Mongoid 中这样做。

我有两个模型:

class ImageUpload
  include Mongoid::Document

  referenced_in :post
end

class Post 
  include Mongoid::Document

  references_many :image_uploads
end

如何选择与任何帖子无关的图片上传?

【问题讨论】:

    标签: database ruby-on-rails-3 mongoid


    【解决方案1】:

    您是否尝试过以下操作:

    ImageUpload.where(:post_id => nil)
    

    【讨论】:

    • 如此明显,但我什至没有想到。谢谢。
    • 一定要加上 :dependent => :nullify 否则你的图片在帖子被删除后仍然会有 post_id
    猜你喜欢
    • 1970-01-01
    • 2011-07-16
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    • 1970-01-01
    • 2011-07-21
    • 2012-02-02
    相关资源
    最近更新 更多