_Article. The table has three columns,
publishedDate. An example of the data stored in this table might look like this:
Columnannotation. 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:
Columnannotation per property, and you must set all behaviors in one annotation, e.g.:
Columnannotation to specify:
primaryKeyconstant exists as a convenience for a
Columnwith these behaviors.
conduitcommand line tool to generate and execute migration scripts. The tool inspects your database types and automatically synchronizes a databases schema to match your them.
_). This convention is discussed later in this guide.
ManagedObjectsubclass to bring your table definition to life. Here's an example:
_Articledeclares those properties. You create and use instances of a managed object subclass like any other object:
Countryhas a property of type
City, and a
Cityhas a property of type
Relateannotation 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.
Relateis 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:
Relateproperty can never be a
List, and therefore can be used in the same way a list is used.
Relateannotation 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
#capitalbecause the name of the inverse property is
cities. This pairing name must match or an error will be thrown.
#namesyntax is a symbol literal.
Relateannotation has optional arguments to further define the relationship. Like
Column, these are optional arguments, e.g.:
City.countrywere required, then a
Citymust always have a
Country. By default, relationships are optional.
rolecolumn is stored as a string. Its value is either "admin" or "user".
readand 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.
Authortype 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:
Serializeso that it is able to be read from a request body, written to a response body, or both. For example:
_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.
ApplicationChannelis declared in.
conduitCLI to generate database migration scripts, it will report all of the
ManagedObjects 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
Serialize-annotated transient property to the
ManagedObjectsubclass, and each time you fetch, remove the join table from the object and place the players in the transient property.