-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 7.0.12
-
Component/s: Associations
-
None
Givens those classes :
class Article include Mongoid::Document embeds_many :comments, order: :body.asc end class Comment include Mongoid::Document embedded_in :article field :body, type: String end
This code doesn't give expected results :
article = Article.new article.comments.criteria # => works without this line article.comments.build(body: 'test') pp article.comments.count # => gives 0 instead of 1 pp article.comments.where(body: 'test').count # => gives 0 instead of 1 pp article.comments.context.documents # gives an empty array
This happens because in article.comments.criteria we load article.comments.criteria.documents and those values are memoized. Elements we add later in the association are ignored and article.comments.criteria.documents always gives the same array. Those values have to be cleaned when we add or remove elements in documents.
- duplicates
-
MONGOID-4672 Default order in `embeds_many` association causes association to use/return stale data
- Closed