更新功能不影响数据库(RAILS)

时间:2015-04-22 10:22:22

标签: ruby-on-rails ruby ruby-on-rails-4 ruby-on-rails-3.2

我正在尝试删除BSON ID。它从对象的数组中删除元素,但不影响数据库。你能告诉我我做错了什么吗?谢谢

  def delete_bookmark
    request_to_be_deleted = params[:d]
    l = request_to_be_deleted.split("'")
    request_to_be_deleted = l[1]
    request_bookmarks = params[:d1]
    l = request_bookmarks.split("'")
    request_bookmarks = l[1]
    b = Bookmark.where(request_id: request_bookmarks).first()
    b1 = b
    req = Request.find(request_to_be_deleted)
    b1[:corsponding_requests].delete(req[:_id])

    b1.update(Hash['corsponding_requests' , b1[:corsponding_requests]])
    session[:request_bookmarks] = request_bookmarks
    asd
    render :action => "bookmark"
  end

书签型号

include Mongoid::Document
  include Mongoid::Timestamps
  field :user_id, type: Mongoid
  field :request_id, type: Mongoid
  field :corsponding_requests, type: Array

  validates_presence_of :user_id , :request_id

  belongs_to :user
  belongs_to :request

1 个答案:

答案 0 :(得分:1)

它不会删除其他mongo集合中的对象,因为mongoid不知道你想做什么 - 只要它关心你,你就得到了一个ids数组

如果您希望mongoid为您创建该链接,那么您需要设置relation - 您所拥有的内容看起来像是单边的n-n关系