更新功能不影响数据库(RAILS)
update function not effecting te database(RAILS )
我正在尝试删除一个 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
它不会删除另一个 mongo 集合中的对象,因为 mongoid 不知道那是你想要做的 - 就它而言,你只是得到了一个数组IDs
如果你想让 mongoid 为你做那个 link 那么你需要设置一个 relation - 你所拥有的看起来像一个单边 n-n 关系
我正在尝试删除一个 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
它不会删除另一个 mongo 集合中的对象,因为 mongoid 不知道那是你想要做的 - 就它而言,你只是得到了一个数组IDs
如果你想让 mongoid 为你做那个 link 那么你需要设置一个 relation - 你所拥有的看起来像一个单边 n-n 关系