_Article
. The table has three columns, id
, contents
, publishedDate
. An example of the data stored in this table might look like this:Column
annotation. This annotation configures the behavior of the associated database column. If a property doesn't have an annotation, the column has default behavior. These behaviors are shown in the table below:bool
ManagedPropertyType
bool
bool
String
bool
bool
bool
Column
annotation per property, and you must set all behaviors in one annotation, e.g.:int
INT
or SERIAL
double
DOUBLE PRECISION
String
TEXT
DateTime
TIMESTAMP
bool
BOOLEAN
Document
JSONB
enum
TEXT
databaseType
of a Column
annotation to specify:Column
annotation.primaryKey
constant exists as a convenience for a Column
with these behaviors.conduit
command line tool to generate and execute migration scripts. The tool inspects your database types and automatically synchronizes a databases schema to match your them.Table
annotation._
). This convention is discussed later in this guide.ManagedObject
subclass to bring your table definition to life. Here's an example:Article
has an id
, contents
and publishedDate
because _Article
declares those properties. You create and use instances of a managed object subclass like any other object:Country
has a property of type City
, and a City
has a property of type Country
.Relate
annotation. The Relate
annotation designates the underlying column as a foreign key column. In this example, the city table has a foreign key column to the country table. Conceptually, then, a city belongs to a country and a country has-one capital city. A city can only belong to one country through this relationship, and that is true of all belongs-to relationship properties.country_id
.Relate
is the inverse of the relationship and is conceptually either a has-one or has-many relationship property. In this example, a country's relationship to its capital is has-one. A relationship is has-many when the type of the inverse property is a ManagedSet
. For example, if we wanted to model a relationship between a country and all of its cities, we'd declare a ManagedSet<City>
property in the country:Relate
property can never be a ManagedSet
. A ManagedSet
is a List
, and therefore can be used in the same way a list is used.Relate
annotation takes at least one argument: a symbol that matches the name of the inverse property. This is what links two relationship properties to each other. In the first example, this argument was #capital
because the name of the inverse property is capital
; likewise, #cities
and cities
. This pairing name must match or an error will be thrown.#name
syntax is a symbol literal.Relate
annotation has optional arguments to further define the relationship. Like Column
, these are optional arguments, e.g.:City.country
were required, then a City
must always have a Country
. By default, relationships are optional.role
column is stored as a string. Its value is either "admin" or "user".read
and is not written when invoking asMap
. Both of these methods are invoked when reading a managed object from a request body, or writing it to a response body.Author
type that stores first and last name as separate columns. Instead of redundantly storing a 'full name' in the database, a transient property can combine the first and last name:Serialize
so that it is able to be read from a request body, written to a response body, or both. For example:Serialize
:_
to prevent it from being used elsewhere in the project. It is preferable to declare one entity per file, and store all entities in the lib/model/
directory of your project.ApplicationChannel
is declared in.conduit
CLI to generate database migration scripts, it will report all of the ManagedObject
s in your application that it was able to find. If a particular type is not listed, it may reveal that you aren't using that type. If you need to ensure that the tooling can see a particular model file that it is not locating, you may import it in your channel.dart
file.Serialize
-annotated transient property to the ManagedObject
subclass, and each time you fetch, remove the join table from the object and place the players in the transient property.