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

Unexpected behaviour on embeds_many association

      I have a a model called "Issue", which embeds many "Articles":

      class Issue
      embedded_in :publication
      embeds_many :articles, :as => :articleable, :class_name => 'Article'

      accepts_nested_attributes_for :articles, :allow_destroy => true, :autosave => true
      end

      class Article
      embedded_in :articleable, polymorphic: true

      accepts_nested_attributes_for :article_image, :allow_destroy => true, :autosave => true
      end

      Everything seems to work fine, but then I try to loop through my articles in my view and an extra article gets build with nil values:

      <% issue.articles.each do |article| %>
      <p><%= article.title %></p>
      <% end %>

      I get:

      1. Some value
      2. nil

      Why in the world is this happening? When I query the exact same "Issue" in the database, then only get 1 article.

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

              Created:
              Updated:
              Resolved: