Basic Usage
We'll cover the following...
Redux-ORM comes with excellent documentation. The main Redux-ORM README, Redux-ORM Primer tutorial, and the API documentation cover the basics very well, but here’s a quick recap.
Defining Model Classes
First, you need to determine your different data types, and how they relate to each other. Think of this in the same way you would set up a database schema, with tables, foreign keys, and so on. Then, declare ES6 classes that extend from Redux-ORM’s Model
class. Like other file types in a Redux app, there’s no specific requirement for where these declarations should live, but you might want to put them into a models.js
file, or a /models
folder in your project
As part of those declarations, add a static fields
section to the class itself that uses Redux-ORM’s relational operators to define what relations this class has. This can be done with three different forms of JS syntax: attaching the declaration to the class variable after it’s been declared; using a static get
function on the class; or using the Class Properties syntax to declare a static
field. You should also declare a "modelName"
property so that table names are correctly generated even if the code is minified.
In Redux-ORM 0.9, the API was updated to allow you to declare what per-instance fields are expected for each ...