Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3104

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

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 5.0.0
    • Component/s: None
    • Labels:

      Description

      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">
      

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: