mongoid/mongoid — Issue #1509: document['key'] not returning the same as document.key
Author: aaronrenner
Created: 2011-12-19 22:02:30+00:00
State: open

I am getting different values back when accessing relationships using [] and the dot notation. Below is a code example

```ruby

require 'mongoid'

class Nurse
include Mongoid::Document
embeds_one :name
end

class Name
include Mongoid::Document
embedded_in :namable, polymorphic: true

field :first_name, type: String

def to_s
first_name
end
end

nurse = Nurse.new(:name => Name.new(:first_name=>"Fred"))

puts "nurse['name'] #{nurse['name']}"
# => nurse['name']
puts "nurse.name #{nurse.name}"
# => nurse.name Fred

```

What is even worse is if I load a parent object from the db, and I change its child object. The dot notation is correct, but the [] notation reflects the old value. It doesn't matter if I save or reload the object, I still get the same behavior.