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

find_or_create_by problem with embedded 1 to n and Hashes

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

      I have an embedded 1 to many relationship that looks like the following:

      class A
        include Mongoid::Documents
        embeds_many :bs
      end
      
      class B
        embedded_in :a
        field :h, type: Hash
      end
      

      When I call the following:

      a = A.new
      a.bs.find_or_create_by(h: {key: "value"})
      a.bs.find_or_create_by(h: {key: "some other value"})
      

      the first call is successful, but the second call gives me:

      NoMethodError: undefined method `new' for nil:NilClass
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            bcassell Ben Cassell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: