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

When using Mongoid::Criteria.includes it remains active on associations

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Associations, Query
    • None

      If we use .includes on a query it seems to be active for the next queries causing errors on some scenarios like this:

       

      instance = Instance.first
      instance.deals.includes(:organization).first
      instance.deals.where(id: 'some-id').only(:name).first
      ActiveModel::MissingAttributeError: Missing attribute: 'organization_id'
      from /usr/local/bundle/gems/mongoid-7.4.3/lib/mongoid/attributes.rb:265:in `read_raw_attribute'
      

      As we can see above when the second query is performed it raises an error that shouldn't be raised.

      Looks like the `includes(:organization)` was cached.

            Assignee:
            Unassigned Unassigned
            Reporter:
            almir.mendes@resultadosdigitais.com.br Almir Mendes
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: