-
Type: Bug
-
Resolution: Duplicate
-
Priority: Unknown
-
None
-
Affects Version/s: 7.4.0
-
Component/s: Attributes
-
None
`attributes` returns a `Hash` or a `Bson::Document` depending on what method was used to fetch the object. It's a hash after `create` and `reload`, but a `Bson::Document` after find. This means that attributes can't be consistently accessed with symbols as keys.
```ruby
class Test
include Mongoid::Document
end
> t = Test.create
=> #<Test _id: 627a49ef69ca9cc6b8bacb59, >
> t.attributes.class
=> Hash
> t1 = Test.find('627a49ef69ca9cc6b8bacb59')
=> #<Test _id: 627a49ef69ca9cc6b8bacb59, >
> t1.attributes.class
=> BSON::Document
> t1.attributes[:_id]
=> BSON::ObjectId('627a49ef69ca9cc6b8bacb59')
> t1.reload.attributes.class
=> Hash
> t1.reload.attributes[:_id]
=> nil
```
- duplicates
-
MONGOID-5365 Change #attributes return value to Hash with a flag
- Closed
- is related to
-
MONGOID-5312 Document attributes method in reference
- Closed