Skip to content

Commit 8bba38c

Browse files
authored
MONGOID-5404 Populate attributes_before_type_cast on read from database (#5347)
* MONGOID-5222 update attributes_before_typecast on read * MONGOID-5222 fix test * MONGOID-5404 change abtc to function like rails * MONGOID-5404 add a release note * MONGOID-5404 update tests * MONGOID-5404 fix docs
1 parent 26f75f1 commit 8bba38c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

source/release-notes/mongoid-8.0.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,26 @@ returns ``true``:
600600
b.name == "Depeche Mode"
601601
end
602602
# => #<Band _id: 62c58e383282a4cbe82bd74b, name: "Depeche Mode">
603+
604+
605+
Changes to the ``attributes_before_type_cast`` Hash
606+
---------------------------------------------------
607+
608+
The ``attributes_before_type_cast`` hash has been changed to function more like
609+
ActiveRecord:
610+
611+
- On instantiation of a new model (without parameters), the
612+
``attributes_before_type_cast`` hash has the same contents as the
613+
``attributes`` hash. If parameters are passed to the initializer, those
614+
values will be stored in the ``attributes_before_type_cast`` hash before
615+
they are ``mongoized``.
616+
- When assigning a value to the model, the ``mongoized`` value (i.e. when
617+
assiging '1' to an Integer field, it is ``mongoized`` to 1) is stored in
618+
the ``attributes`` hash, whereas the raw value (i.e. '1') is stored in the
619+
``attributes_before_type_cast`` hash.
620+
- When saving, creating (i.e. using the ``create!`` method), or reloading the
621+
model, the ``attributes_before_type_cast`` hash is reset to have the same
622+
contents as the ``attributes`` hash.
623+
- When reading a document from the database, the ``attributes_before_type_cast``
624+
hash contains the attributes as they appear in the database, as opposed to
625+
their ``demongoized`` form.

0 commit comments

Comments
 (0)