# Read objects

The Read objects action node adds existing objects into a [runtime-only data source](https://docs.appfarm.io/reference/apps/data/data-sources#database-connected-and-runtime-only-data-sources). The existing objects can be read from another data source or directly from the database.

## Usage

This action node is used to populate runtime-only data sources with objects as needed during runtime. Read objects adds an exact copy of an object in the target data source – it is the same object as in the source data source (or the database) with the same **ID**. To instead duplicate an object, use [Duplicate objects](https://docs.appfarm.io/library/action-nodes/duplicate-objects).

A common use case for Read objects is to copy an object for editing. As it is copied to a runtime-only data source any changes only exist in the client user's session until they are persisted.

Read objects can also be used to improve performance by only populating a data source when it will be used. The objects can be added directly from the database, but if the required objects are already present in another data source reading them from there will be more performant.

### Example

{% tabs %}
{% tab title="Edit an existing object" %}
Your app manages the various products you have for sale. All the products are accessed and updated via a [database-connected data source](https://docs.appfarm.io/reference/apps/data/data-sources#database-connected-and-runtime-only-data-sources). When you edit a product, the change is immediately stored in the database. Instead, you'd like to be able to edit a product but then choose to cancel or save the changes.

To do this, trigger an action when you want to edit a product that uses Read objects to read that product object into a runtime-only, single-cardinality data source. Adjust the edit UI to be bound to the properties in this new data source and add a `Cancel` and `Save` button.

When the `Save` button is clicked, run a [Persist objects action node](https://docs.appfarm.io/library/action-nodes/persist-objects) to save the changes to the database and navigate back to the previous view.

When the Cancel button is clicked, just navigate back to the previous view. The changes will still exist in the runtime-only data source but will not be saved in the database. Optionally, run a [Delete objects action node](https://docs.appfarm.io/library/action-nodes/delete-objects) to remove the project object (and all the changes) from the runtime-only data source.
{% endtab %}
{% endtabs %}

## Properties

<table><thead><tr><th width="203">Property</th><th>Description</th></tr></thead><tbody><tr><td><strong>Data Source</strong></td><td>Select a runtime-only data source to read the objects into. If the data source is single-cardinality, ensure that it does not have <strong>Auto Create</strong> selected.</td></tr><tr><td><strong>Set Selected</strong></td><td><em>Available if the selected</em> <strong>Data Source</strong> <em>is a many-cardinality data source.</em> <br><br>Set the newly read objects as <a href="../../../reference/platform-concepts/objects#object-selection">selected</a>. If the data source already contains selected objects, they will remain selected.</td></tr><tr><td><strong>Operation</strong></td><td><p>Select how existing objects in the selected <strong>Data Source</strong> will be treated. If the selected <strong>Data Source</strong> is a single-cardinality data source the operation will be restricted to <code>Replace All Objects</code>.</p><ul><li><code>Replace All Objects</code>: Remove any existing objects before reading in the objects. </li><li><code>Add to Data Source (replace duplicates)</code>: Keep any existing objects. If an existing object has the same <strong>ID</strong> as an object being read into the data source, it will be replaced by the newly read object.</li></ul></td></tr><tr><td><strong>Read from other</strong></td><td>Read objects from another data source. If this is not selected, the objects will be read directly from the database. It is more performant to read from another data source.</td></tr><tr><td><strong>From Data Source</strong></td><td><em>Available if</em> <strong>Read from other</strong> <em>is selected.</em><br><br>Select a data source to read the objects from.</td></tr><tr><td><strong>Selection</strong></td><td><p><em>Available if</em> <strong>Read from other</strong> <em>is selected and the</em> <strong>From Data Source</strong> <em>is a many-cardinality data source.</em><br><br>Define the objects to read.</p><ul><li><code>All objects</code></li><li><a href="../../../reference/platform-concepts/objects#object-selection"><code>Selected object(s)</code></a></li><li><a href="../../../reference/platform-concepts/objects#object-in-context"><code>Object in context</code></a></li><li><code>Filtered selection</code></li></ul></td></tr><tr><td><strong>Filter</strong></td><td><em>Available when <strong>Read from other</strong> is not selected or when</em> <strong>Selection</strong> <em>is Filtered selection.</em><br><br>Define the <a href="../../reference/platform-concepts/filters">filter</a> to apply to the data source. If this property is visible, a filter must be defined otherwise no objects will be read.</td></tr><tr><td><strong>Conditional Filters</strong></td><td><p><em>Available when a <strong>Filter</strong> is applied.</em></p><p></p><p>Add conditional filters that can be enabled or disabled runtime. All enabled filters will be applied in addition to the regular filter.</p></td></tr><tr><td><strong>Sorting</strong></td><td>Add <a href="../sort-objects#sorting">sorting rules</a>. The objects will be sorted before they are read in to the data source.</td></tr><tr><td><strong>Skip First</strong></td><td>Skip the first n records read.</td></tr><tr><td><strong>Limit Result</strong></td><td>Limit the maximum number of objects read into the data source.</td></tr><tr><td><strong>Return Total Object Count</strong></td><td><em>Available when <strong>Read from other</strong> is not selected, and <strong>Skip First</strong> or <strong>Limit Result</strong> is applied.</em><br><br>Retrieve the number of objects that would be returned if Skip and Limit had not been applied.</td></tr><tr><td><strong>Total Object Count Property</strong></td><td><em>Available when <strong>Return Total Object Count</strong> is selected.</em><br><br>Select a property to write the Total Object Count to.</td></tr></tbody></table>
