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

belongs_to association returning nil

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

      I guess the easiest way to express this issue is via code. Am I missing something here that shouldn't be able to do?

      class A
        has_many :bs
        embeds_many :cs
      end
      
      class B
        belongs_to :a
        belongs_to :c
      end
      
      class C
        embedded_in: a
        has_many :bs
      end
      
      b.c_id = c.id
      b.save!
      p b.c #=> nil
      p b.c_id #=> "5074ad493573c6e72a000002"
      p c.bs #=> [#<B _id ...>]
      

      As you can see, b.c is returning nil when I expected it to return an object of class C

            Assignee:
            Unassigned Unassigned
            Reporter:
            lancecarlson Lance Carlson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: