-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorporate feedback about creating objects for JS/TS
- Loading branch information
Showing
3 changed files
with
27 additions
and
21 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...avascript/model-data/object-models-define-embedded-object-js-ts-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
In the Node.js SDK, to define an embedded object, set ``embedded`` | ||
In the JavaScript SDK, to define an embedded object, set ``embedded`` | ||
to ``true``. You can reference an embedded object type from parent object types | ||
in the same way as you would define a relationship. |
23 changes: 13 additions & 10 deletions
23
...es/api-details/javascript/model-data/object-models-object-model-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
You can define SDK models as JavaScript classes that extend ``Realm.Object`` | ||
(like most of the examples on this page). Or you can define models as | ||
JavaScript objects. | ||
You can define SDK models as JavaScript classes that extend ``Realm.Object``. | ||
|
||
When you define models as JavaScript classes that extend ``Realm.Object``, | ||
you can pass those model objects directly to the database. Prefer this approach | ||
when possible. | ||
When you create objects, use an object literal. This lets you create an | ||
**unmanaged** object, and pass it to the database when it makes sense to do so. | ||
|
||
If you do define a model that does not extend ``Realm.Object``, you cannot pass | ||
the model directly to the database. Instead, you pass only the schema to the | ||
database that manages the object. | ||
Do not use ``new`` to construct a new object instance. If you use ``new`` with | ||
class-based models, this creates a new **managed** object, which has the | ||
following side effects: | ||
|
||
.. TODO: Provide more info about why you would choose one of these approaches over the other | ||
- Constructing a ``new`` object calls the ``realm.create()`` method, which can | ||
only be used in a write transcation. | ||
- Constructing a ``new`` object has complications when the object contains or | ||
is itself an embedded object. | ||
|
||
For more information about object creation and managed objects, refer to | ||
:ref:`sdks-crud-create` and :ref:`sdks-create-specific-object-types`. |
23 changes: 13 additions & 10 deletions
23
...es/api-details/typescript/model-data/object-models-object-model-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
You can define SDK models as TypeScript classes that extend ``Realm.Object`` | ||
(like most of the examples on this page). Or you can define models as | ||
TypeScript objects. | ||
You can define SDK models as TypeScript classes that extend ``Realm.Object``. | ||
|
||
When you define models as TypeScript classes that extend ``Realm.Object``, | ||
you can pass those model objects directly to the database. Prefer this approach | ||
when possible. | ||
When you create objects, use an object literal. This lets you create an | ||
**unmanaged** object, and pass it to the database when it makes sense to do so. | ||
|
||
If you do define a model that does not extend ``Realm.Object``, you cannot pass | ||
the model directly to the database. Instead, you pass only the schema to the | ||
database that manages the object. | ||
Do not use ``new`` to construct a new object instance. If you use ``new`` with | ||
class-based models, this creates a new **managed** object, which has the | ||
following side effects: | ||
|
||
.. TODO: Provide more info about why you would choose one of these approaches over the other | ||
- Constructing a ``new`` object calls the ``realm.create()`` method, which can | ||
only be used in a write transcation. | ||
- Constructing a ``new`` object has complications when the object contains or | ||
is itself an embedded object. | ||
|
||
For more information about object creation and managed objects, refer to | ||
:ref:`sdks-crud-create` and :ref:`sdks-create-specific-object-types`. |