File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -629,14 +629,23 @@ being operated on:
629
629
}
630
630
631
631
When defining a default value as a ``Proc``, Mongoid will apply the default
632
- after all other attributes are set. To have the default be applied before
633
- the other attributes are set, use the ``pre_processed: true`` field option:
632
+ after all other attributes are set and associations are initialized.
633
+ To have the default be applied before the other attributes are set,
634
+ use the ``pre_processed: true`` field option:
634
635
635
636
.. code-block:: ruby
636
637
637
638
field :fulfill_by, type: Time, default: ->{ Time.now + 3.days },
638
639
pre_processed: true
639
640
641
+ The ``pre_processed: true`` option is also necessary when specifying a custom
642
+ default value via a ``Proc`` for the ``_id`` field, to ensure the ``_id``
643
+ is set correctly via associations:
644
+
645
+ .. code-block:: ruby
646
+
647
+ field :_id, type: String, default: -> { 'hello' }, pre_processed: true
648
+
640
649
641
650
.. _storage-field-names:
642
651
You can’t perform that action at this time.
0 commit comments