class Student < CouchRest::Model::Base
collection_of :phones
def add_phone(new_phone)
#this does not work
#new_phone_ids_list = phone_ids << new_phone.id
#this works
new_phone_ids_list = phone_ids + [new_phone.id]
self.update_attributes(:phone_id => new_phone_ids_list)
end
end
所不同的是,當我使用phone_ids < < new_phone.id創建一個新的列表,並更新CouchDB的,這是行不通的。但是,如果我使用phone_ids + [new_phone.id],更新將起作用。我明白phone_ids + [new_phone.id]
會返回一個新的實例,但無法弄清楚,爲什麼phone_ids << new_phone.id
不工作無法更新軌道模型
「到收集IDS屬性(group_ids)所做的任何手動更改,除非更換,將需要CollectionOfProxy爲兩組數據的重新加載到保持同步的」 http://www.rubydoc。 info/github/couchrest/couchrest_model/CouchRest%2FModel%2FAssociations%2FlassMethods%3Acollection_of – bumpy
@bumpy非常感謝!這正是我正在尋找的! – user2569579
@bumpy我不知道如何將答案標記爲正確答案。 – user2569579