Skip to content

Commit cef142b

Browse files
authored
MONGOID-5072 Document readonly attributes ignoring assignment (#5282)
* MONGOID-5072 document readonly functionality * MONGOID-5072 update language
1 parent 884fade commit cef142b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

docs/reference/fields.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ The valid types for fields are as follows:
7777
- ``Regexp``
7878
- ``Set``
7979
- ``String``
80-
- ``Mongoid::StringifiedSymbol``, which may be specified simply as
80+
- ``Mongoid::StringifiedSymbol``, which may be specified simply as
8181
``StringifiedSymbol`` in the scope of a class which included
8282
``Mongoid::Document``.
8383
- ``Symbol``
@@ -1304,6 +1304,19 @@ a ``ReadonlyAttribute`` exception will be raised:
13041304
band.update_attribute(:name, "Tool") # Raises the error.
13051305
band.remove_attribute(:name) # Raises the error.
13061306

1307+
Assignments to read-only attributes using their setters will be ignored:
1308+
1309+
.. code-block:: ruby
1310+
1311+
b = Band.create!(name: "The Rolling Stones")
1312+
# => #<Band _id: 6287a3d5d1327a5292535383, name: "The Rolling Stones", origin: nil>
1313+
b.name = "The Smashing Pumpkins"
1314+
# => "The Smashing Pumpkins"
1315+
b.name
1316+
# => "The Rolling Stones"
1317+
1318+
Calls to atomic persistence operators, like ``bit`` and ``inc``, will persist
1319+
changes to readonly fields.
13071320

13081321
Timestamp Fields
13091322
================

0 commit comments

Comments
 (0)