-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: 8.1.5, 8.0.8, 9.0.1
-
Component/s: Associations
-
None
-
Ruby Drivers
-
Not Needed
-
After upgrading from v7.5.4 to v8.0.8, I noticed that accessing the parent after using query projection will no longer work. This is also failing in the latest version.
#!/usr/bin/env ruby require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'mongoid', '9.0.0' end require 'mongoid' Mongoid.configure { |c| c.clients.default = { hosts: ['localhost'], database: 'test' } } puts Mongoid::VERSION puts Mongo::VERSION # From https://github.com/mongodb/mongoid/blob/master/spec/mongoid/association/embedded/embeds_many_models.rb class EmmCongress include Mongoid::Document include Mongoid::Timestamps embeds_many :legislators, class_name: 'EmmLegislator' end class EmmLegislator include Mongoid::Document embedded_in :congress, class_name: 'EmmCongress' field :a, type: Integer, default: 0 field :b, type: Integer, default: 0 end # From https://github.com/mongodb/mongoid/blob/master/spec/mongoid/association/embedded/embeds_many_query_spec.rb # setup congress = EmmCongress.new congress.legislators << EmmLegislator.new(a: 1, b: 2) congress.save! # let congress = EmmCongress.only(:id, "legislators.a").first p congress # returns #<EmmCongress _id: 669dca95b82c2d0201f76ce3, created_at: nil, updated_at: nil> legislator = congress.legislators.first p legislator.congress # expect to get same value as above but instead got ActiveModel::MissingAttributeError (Missing attribute: 'congress') # this works in 7.5.4