Mongoid::Relations::Targets::Enumerable#last doesn't respect newly added documents when there are already persisted documents (no matter if enum loaded or not)

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • 5.0.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Given:

      class Post
        include Mongoid::Document
        has_many :comments
      end
      
      class Comment
        include Mongoid::Document
        belongs_to :post
      end
      

      Enum not loaded

      1.9.3p392 :006 >   p = Post.create
       => #<Post _id: 51b984bbf52876e795000001, >
      1.9.3p392 :007 > p.comments.create
       => #<Comment _id: 51b984c2f52876e795000002, post_id: "51b984bbf52876e795000001">
      1.9.3p392 :008 > p.comments.new
       => #<Comment _id: 51b984c7f52876e795000003, post_id: "51b984bbf52876e795000001">
      1.9.3p392 :009 > p.comments.last
       => #<Comment _id: 51b984c2f52876e795000002,post_id: "51b984bbf52876e795000001">
      

      Enum loaded

      1.9.3p392 :011 > p.comments.entries
       => [#<Comment _id: 51b984c2f52876e795000002,post_id: "51b984bbf52876e795000001">, #<Comment _id: 51b984c7f52876e795000003, post_id: "51b984bbf52876e795000001">]
      1.9.3p392 :012 > p.comments._loaded?
       => true
      1.9.3p392 :013 > p.comments.last
       => #<Comment _id: 51b984c2f52876e795000002, post_id: "51b984bbf52876e795000001">
      

              Assignee:
              Unassigned
              Reporter:
              silentshade
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: