-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
I'm seeing that if I have a has_many reference relation and I save something in the collection, it resets the collection after the save forcing me to reload the collection to retrieve the new item. Example:
class Book include Mongoid::Document field :name has_many :pages end class Page include Mongoid::Document belongs_to :book field :text end book = Book.create(:name => "A Tale of Two Cities") book.pages.build(:text => "It was the best of times, it was the worst of times.") book.pages.length # 1 book.pages.count # 0 book.pages[0].save # true book.pages.length # 0 book.pages # [] book.pages.count # 1
I either have to execute book.reload or book.pages(true) in order to get the page. This does not happen with embedded documents as far as I can tell.