strapi/docs/.vuepress/dist/assets/js/16.5c84c402.js
2018-10-05 17:24:17 +02:00

1 line
78 KiB
JavaScript

(window.webpackJsonp=window.webpackJsonp||[]).push([[16],{223:function(t,s,a){"use strict";a.r(s);var n=a(0),e=Object(n.a)({},function(){this.$createElement;this._self._c;return this._m(0)},[function(){var t=this,s=t.$createElement,a=t._self._c||s;return a("div",{staticClass:"content"},[a("h1",{attrs:{id:"models"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#models","aria-hidden":"true"}},[t._v("#")]),t._v(" Models")]),t._v(" "),a("p",[t._v("Strapi comes installed with a powerful Object-Relational-Mapper (ORM) called Waterline,\na datastore-agnostic tool that dramatically simplifies interaction with one or more databases.")]),t._v(" "),a("p",[t._v("Models represent a structure of data which requires persistent storage. The data may live in any data-store\nbut is interfaced in the same way. This allows your users to live in PostgreSQL and your user preferences\nto live in MongoDB and you will interact with the data models in the exact same way.")]),t._v(" "),a("p",[t._v("If you're using MySQL, a model might correspond to a table. If you're using MongoDB, it might correspond\nto a collection. In either case, the goal is to provide a simple, modular way of managing data without\nrelying on any one type of database.")]),t._v(" "),a("p",[t._v("Models are defined in the "),a("code",[t._v("./api/<apiName>/models")]),t._v(" directory.")]),t._v(" "),a("h2",{attrs:{id:"model-settings"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#model-settings","aria-hidden":"true"}},[t._v("#")]),t._v(" Model settings")]),t._v(" "),a("p",[t._v("The following properties can be specified at the top level of your model definition to override\nthe defaults for that particular model.")]),t._v(" "),a("p",[t._v("For example, this a basic model "),a("code",[t._v("Pet")]),t._v(":")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"identity"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"pet"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"connection"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"mongoDBServer"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"schema"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"name"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"gender"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"enum"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{attrs:{class:"token string"}},[t._v('"male"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"female"')]),a("span",{attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"age"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"int"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"max"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token number"}},[t._v("100")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"birthDate"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"date"')]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"breed"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"autoPK"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"autoCreatedAt"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"autoUpdatedAt"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])]),a("h3",{attrs:{id:"schema"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#schema","aria-hidden":"true"}},[t._v("#")]),t._v(" schema")]),t._v(" "),a("p",[t._v("A flag to toggle schemaless or schema mode in databases that support schemaless data structures.\nIf turned off, this will allow you to store arbitrary data in a record. If turned on, only attributes\ndefined in the model's attributes object will be stored.")]),t._v(" "),a("p",[t._v("For adapters that don't require a schema, such as MongoDB or Redis, the "),a("code",[t._v("schema")]),t._v(" key is set to "),a("code",[t._v("false")]),t._v(".")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"schema"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token operator"}},[t._v("|")]),a("span",{attrs:{class:"token boolean"}},[t._v("false")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h3",{attrs:{id:"connection"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#connection","aria-hidden":"true"}},[t._v("#")]),t._v(" connection")]),t._v(" "),a("p",[t._v("The configured database connection where this model will fetch and save its data.\nDefaults to "),a("code",[t._v("defaultSQLite")]),t._v(", the default connection that uses the "),a("code",[t._v("waterline-sqlite3")]),t._v(" adapter.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"connection"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"mongoDBServer"')]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h3",{attrs:{id:"identity"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#identity","aria-hidden":"true"}},[t._v("#")]),t._v(" identity")]),t._v(" "),a("p",[t._v("The lowercase unique key for the model. By default, a model's identity is inferred automatically\nby lowercasing its filename. You should never change this property on your models.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"identity"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"petModel"')]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h3",{attrs:{id:"globalid"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#globalid","aria-hidden":"true"}},[t._v("#")]),t._v(" globalId")]),t._v(" "),a("p",[t._v("This flag changes the global name by which you can access your model (if the globalization of models\nis enabled). You should never change this property on your models.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"globaId"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"pets"')]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("p",[t._v("For example to access to your model function:")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("Pets"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("find")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("exec")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("error"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" pets"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("error"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("log")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("error"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),a("span",{attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("false")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n console"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("log")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("pets"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),a("h3",{attrs:{id:"autopk"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#autopk","aria-hidden":"true"}},[t._v("#")]),t._v(" autoPK")]),t._v(" "),a("p",[t._v("A flag to toggle the automatic definition of a primary key in your model.\nThe details of this default primary key vary between adapters. In any case, the primary keys generated\nby "),a("code",[t._v("autoPK")]),t._v(" will be unique. If turned off no primary key will be created by default, and you will need\nto define one manually using "),a("code",[t._v("primaryKey: true")]),t._v(" for one of the model attributes.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"autoPK"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token operator"}},[t._v("|")]),a("span",{attrs:{class:"token boolean"}},[t._v("false")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h3",{attrs:{id:"autocreatedat"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#autocreatedat","aria-hidden":"true"}},[t._v("#")]),t._v(" autoCreatedAt")]),t._v(" "),a("p",[t._v("A flag to toggle the automatic definition of a "),a("code",[t._v("createdAt")]),t._v(" attribute in your model.\nBy default, "),a("code",[t._v("createdAt")]),t._v(" is an attribute which will be automatically set when a record is created with\nthe current timestamp.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"autoCreatedAt"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token operator"}},[t._v("|")]),a("span",{attrs:{class:"token boolean"}},[t._v("false")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h3",{attrs:{id:"autoupdatedat"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#autoupdatedat","aria-hidden":"true"}},[t._v("#")]),t._v(" autoUpdatedAt")]),t._v(" "),a("p",[t._v("A flag to toggle the automatic definition of a "),a("code",[t._v("updatedAt")]),t._v(" attribute in your model.\nBy default, "),a("code",[t._v("updatedAt")]),t._v(" is an attribute which will be automatically set with the current timestamp\nevery time a record is updated.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"autoUpdatedAt"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token operator"}},[t._v("|")]),a("span",{attrs:{class:"token boolean"}},[t._v("false")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h3",{attrs:{id:"tablename"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#tablename","aria-hidden":"true"}},[t._v("#")]),t._v(" tableName")]),t._v(" "),a("p",[t._v("You can define a custom name for the physical collection in your adapter by adding a "),a("code",[t._v("tableName")]),t._v("\nattribute. This isn't just for tables. In MySQL, PostgreSQL, Oracle, etc. this setting refers\nto the name of the table, but in MongoDB or Redis, it refers to the collection, and so forth.\nIf no "),a("code",[t._v("tableName")]),t._v(" is specified, Waterline will use the model's "),a("code",[t._v("identity")]),t._v(" as its "),a("code",[t._v("tableName")]),t._v(".")]),t._v(" "),a("p",[t._v("This is particularly useful for working with pre-existing/legacy databases.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"tableName"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"pets_table"')]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h3",{attrs:{id:"attributes"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#attributes","aria-hidden":"true"}},[t._v("#")]),t._v(" attributes")]),t._v(" "),a("p",[t._v("Model attributes are basic pieces of information about a model.\nA model called "),a("code",[t._v("Pet")]),t._v(" might have attributes called "),a("code",[t._v("name")]),t._v(", "),a("code",[t._v("gender")]),t._v(", "),a("code",[t._v("age")]),t._v(",\n"),a("code",[t._v("birthday")]),t._v(" and "),a("code",[t._v("breed")]),t._v(".")]),t._v(" "),a("p",[t._v("Options can be used to enforce various constraints and add special enhancements to model attributes.")]),t._v(" "),a("h4",{attrs:{id:"type"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#type","aria-hidden":"true"}},[t._v("#")]),t._v(" type")]),t._v(" "),a("p",[t._v("Specifies the type of data that will be stored in this attribute. One of:")]),t._v(" "),a("ul",[a("li",[a("code",[t._v("string")])]),t._v(" "),a("li",[a("code",[t._v("text")])]),t._v(" "),a("li",[a("code",[t._v("integer")])]),t._v(" "),a("li",[a("code",[t._v("float")])]),t._v(" "),a("li",[a("code",[t._v("date")])]),t._v(" "),a("li",[a("code",[t._v("datetime")])]),t._v(" "),a("li",[a("code",[t._v("boolean")])]),t._v(" "),a("li",[a("code",[t._v("binary")])]),t._v(" "),a("li",[a("code",[t._v("array")])]),t._v(" "),a("li",[a("code",[t._v("json")])])]),t._v(" "),a("p",[t._v("Defaults to "),a("code",[t._v("string")]),t._v(" if not specified.")]),t._v(" "),a("h3",{attrs:{id:"validations"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#validations","aria-hidden":"true"}},[t._v("#")]),t._v(" Validations")]),t._v(" "),a("p",[t._v("Strapi bundles support for automatic validations of your models' attributes.\nAny time a record is updated, or a new record is created, the data for each attribute will\nbe checked against all of your predefined validation rules. This provides a convenient failsafe\nto ensure that invalid entries don't make their way into your application's database(s).")]),t._v(" "),a("p",[t._v("Validations are defined directly in your collection attributes.")]),t._v(" "),a("ul",[a("li",[a("code",[t._v("after")]),t._v(" (date): Checks if string date in this record is after the specified "),a("code",[t._v("Date")]),t._v(".\nMust be valid JavaScript "),a("code",[t._v("Date")]),t._v(".")]),t._v(" "),a("li",[a("code",[t._v("alpha")]),t._v(" (boolean): Checks if string in this record contains only letters (a-zA-Z).")]),t._v(" "),a("li",[a("code",[t._v("alphadashed")]),t._v(" (boolean): Checks if string in this record contains only numbers and/or dashes.")]),t._v(" "),a("li",[a("code",[t._v("alphanumeric")]),t._v(" (boolean): Checks if string in this record contains only letters and numbers.")]),t._v(" "),a("li",[a("code",[t._v("alphanumericdashed")]),t._v(" (boolean): Checks if string in this record contains only numbers and/or\nletters and/or dashes.")]),t._v(" "),a("li",[a("code",[t._v("array")]),t._v(" (boolean): Checks if this record is a valid JavaScript array object.\nStrings formatted as arrays will fail.")]),t._v(" "),a("li",[a("code",[t._v("before")]),t._v(" (date): Checks if string in this record is a date that's before the specified date.")]),t._v(" "),a("li",[a("code",[t._v("binary")]),t._v(" (boolean): Checks if this record is a valid binary data. Strings will pass.")]),t._v(" "),a("li",[a("code",[t._v("boolean")]),t._v(" (boolean): Checks if this record is a valid boolean. Strings will fail.")]),t._v(" "),a("li",[a("code",[t._v("contains")]),t._v(" (string): Checks if string in this record contains the seed.")]),t._v(" "),a("li",[a("code",[t._v("creditcard")]),t._v(" (boolean): Checks if string in this record is a credit card.")]),t._v(" "),a("li",[a("code",[t._v("date")]),t._v(" (boolean): Checks if string in this record is a date takes both strings and JavaScript.")]),t._v(" "),a("li",[a("code",[t._v("datetime")]),t._v(" (boolean): Checks if string in this record looks like a JavaScript "),a("code",[t._v("datetime")]),t._v(".")]),t._v(" "),a("li",[a("code",[t._v("decimal")]),t._v(" (boolean): Checks if it contains a decimal or is less than 1.")]),t._v(" "),a("li",[a("code",[t._v("email")]),t._v(" (boolean): Checks if string in this record looks like an email address.")]),t._v(" "),a("li",[a("code",[t._v("empty")]),t._v(" (boolean): Checks if the entry is empty. Arrays, strings, or arguments objects with\na length of 0 and objects with no\nown enumerable properties are considered empty.")]),t._v(" "),a("li",[a("code",[t._v("equals")]),t._v(" (integer): Checks if string in this record is equal to the specified value.\nThey must match in both value and type.")]),t._v(" "),a("li",[a("code",[t._v("falsey")]),t._v(" (boolean): Would a Javascript engine register a value of "),a("code",[t._v("false")]),t._v(" on this?.")]),t._v(" "),a("li",[a("code",[t._v("finite")]),t._v(" (boolean): Checks if given value is, or can be coerced to, a finite number.\nThis is not the same as native "),a("code",[t._v("isFinite")]),t._v("\nwhich will return "),a("code",[t._v("true")]),t._v(" for booleans and empty strings.")]),t._v(" "),a("li",[a("code",[t._v("float")]),t._v(" (boolean): Checks if string in this record is of the number type float.")]),t._v(" "),a("li",[a("code",[t._v("hexadecimal")]),t._v(" (boolean): Checks if string in this record is a hexadecimal number.")]),t._v(" "),a("li",[a("code",[t._v("hexColor")]),t._v(" (boolean): Checks if string in this record is a hexadecimal color.")]),t._v(" "),a("li",[a("code",[t._v("in")]),t._v(" (array): Checks if string in this record is in the specified array of allowed\nstring values.")]),t._v(" "),a("li",[a("code",[t._v("int")]),t._v(" (boolean): Check if string in this record is an integer.")]),t._v(" "),a("li",[a("code",[t._v("integer")]),t._v(" (boolean): Check if string in this record is an integer. Alias for "),a("code",[t._v("int")]),t._v(".")]),t._v(" "),a("li",[a("code",[t._v("ip")]),t._v(" (boolean): Checks if string in this record is a valid IP (v4 or v6).")]),t._v(" "),a("li",[a("code",[t._v("ipv4")]),t._v(" (boolean): Checks if string in this record is a valid IP v4.")]),t._v(" "),a("li",[a("code",[t._v("ipv6")]),t._v(" (boolean): Checks if string in this record is aa valid IP v6.")]),t._v(" "),a("li",[a("code",[t._v("json")]),t._v(" (boolean): Checks if the record is a JSON.")]),t._v(" "),a("li",[a("code",[t._v("lowercase")]),t._v(" (boolean): Check if string in this record is in all lowercase.")]),t._v(" "),a("li",[a("code",[t._v("max")]),t._v(" (integer): max value for an integer.")]),t._v(" "),a("li",[a("code",[t._v("maxLength")]),t._v(" (integer):")]),t._v(" "),a("li",[a("code",[t._v("min")]),t._v(" (integer): min value for an integer.")]),t._v(" "),a("li",[a("code",[t._v("minLength")]),t._v(" (integer):")]),t._v(" "),a("li",[a("code",[t._v("notContains")]),t._v(" (string): Checks if string in this record doesn't contain the seed.")]),t._v(" "),a("li",[a("code",[t._v("notIn")]),t._v(" (array): does the value of this model attribute exist inside of the defined\nvalidator value (of the same type).\nTakes strings and arrays.")]),t._v(" "),a("li",[a("code",[t._v("notNull")]),t._v(" (boolean): does this not have a value of "),a("code",[t._v("null")]),t._v(" ?.")]),t._v(" "),a("li",[a("code",[t._v("null")]),t._v(" (boolean): Checks if string in this record is null.")]),t._v(" "),a("li",[a("code",[t._v("number")]),t._v(" (boolean): Checks if this record is a number. "),a("code",[t._v("NaN")]),t._v(" is considered a number.")]),t._v(" "),a("li",[a("code",[t._v("numeric")]),t._v(" (boolean): Checks if string in this record contains only numbers.")]),t._v(" "),a("li",[a("code",[t._v("object")]),t._v(" (boolean): Checks if this attribute is the language type of Object.\nPasses for arrays, functions, objects,\nregexes, new Number(0), and new String('') !")]),t._v(" "),a("li",[a("code",[t._v("regex")]),t._v(" (regex): Checks if the record matches the specific regex.")]),t._v(" "),a("li",[a("code",[t._v("required")]),t._v(" (boolean): Must this model attribute contain valid data before a new\nrecord can be created?.")]),t._v(" "),a("li",[a("code",[t._v("string")]),t._v(" (boolean): Checks if the record is a string.")]),t._v(" "),a("li",[a("code",[t._v("text")]),t._v(" (boolean): Checks if the record is a text.")]),t._v(" "),a("li",[a("code",[t._v("truthy")]),t._v(" (boolean): Would a Javascript engine register a value of "),a("code",[t._v("false")]),t._v(" on this?")]),t._v(" "),a("li",[a("code",[t._v("undefined")]),t._v(" (boolean): Would a JavaScript engine register this thing as have the\nvalue "),a("code",[t._v("undefined")]),t._v("?")]),t._v(" "),a("li",[a("code",[t._v("uppercase")]),t._v(" (boolean): Checks if string in this record is uppercase.")]),t._v(" "),a("li",[a("code",[t._v("url")]),t._v(" (boolean): Checks if string in this record is a URL.")]),t._v(" "),a("li",[a("code",[t._v("urlish")]),t._v(" (boolean): Checks if string in this record contains something that looks like\na route, ending with a file extension.")]),t._v(" "),a("li",[a("code",[t._v("uuid")]),t._v(" (boolean): Checks if string in this record is a UUID (v3, v4, or v5).")]),t._v(" "),a("li",[a("code",[t._v("uuidv3")]),t._v(" (boolean): Checks if string in this record is a UUID (v3).")]),t._v(" "),a("li",[a("code",[t._v("uuidv4")]),t._v(" (boolean): Checks if string in this record is a UUID (v4).")])]),t._v(" "),a("h4",{attrs:{id:"defaultsto"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#defaultsto","aria-hidden":"true"}},[t._v("#")]),t._v(" defaultsTo")]),t._v(" "),a("p",[t._v("When a record is created, if no value was supplied, the record will be created with the specified\n"),a("code",[t._v("defaultsTo")]),t._v(" value.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"usersGroup"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"defaultsTo"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"guess"')]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h4",{attrs:{id:"autoincrement"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#autoincrement","aria-hidden":"true"}},[t._v("#")]),t._v(" autoIncrement")]),t._v(" "),a("p",[t._v("Sets up the attribute as an auto-increment key. When a new record is added to the model,\nif a value for this attribute is not specified, it will be generated by incrementing the most recent\nrecord's value by one.")]),t._v(" "),a("p",[t._v("Attributes which specify "),a("code",[t._v("autoIncrement")]),t._v(" should always be of "),a("code",[t._v("type: integer")]),t._v(".\nAlso, bear in mind that the level of support varies across different datastores.\nFor instance, MySQL will not allow more than one auto-incrementing column per table.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"placeInLine"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"integer"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"autoIncrement"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h4",{attrs:{id:"unique"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#unique","aria-hidden":"true"}},[t._v("#")]),t._v(" unique")]),t._v(" "),a("p",[t._v("Ensures no two records will be allowed with the same value for the target attribute.\nThis is an adapter-level constraint, so in most cases this will result in a unique index on the\nattribute being created in the underlying datastore.")]),t._v(" "),a("p",[t._v("Defaults to "),a("code",[t._v("false")]),t._v(" if not specified.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"username"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"unique"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h4",{attrs:{id:"primarykey"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#primarykey","aria-hidden":"true"}},[t._v("#")]),t._v(" primaryKey")]),t._v(" "),a("p",[t._v("Use this attribute as the the primary key for the record. Only one attribute per model can be the\n"),a("code",[t._v("primaryKey")]),t._v(". Defaults to "),a("code",[t._v("false")]),t._v(" if not specified.")]),t._v(" "),a("p",[t._v("This should never be used unless "),a("code",[t._v("autoPK")]),t._v(" is set to "),a("code",[t._v("false")]),t._v(".")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"uuid"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"primaryKey"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h4",{attrs:{id:"enum"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#enum","aria-hidden":"true"}},[t._v("#")]),t._v(" enum")]),t._v(" "),a("p",[t._v("A special validation property which only saves data which matches a whitelisted set of values.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"gender"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"enum"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{attrs:{class:"token string"}},[t._v('"male"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"female"')]),a("span",{attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h4",{attrs:{id:"size"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#size","aria-hidden":"true"}},[t._v("#")]),t._v(" size")]),t._v(" "),a("p",[t._v("If supported in the adapter, can be used to define the size of the attribute.\nFor example in MySQL, "),a("code",[t._v("size")]),t._v(" can be specified as a number ("),a("code",[t._v("n")]),t._v(") to create a column with the SQL\ndata type: "),a("code",[t._v("varchar(n)")]),t._v(".")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"name"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"size"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token number"}},[t._v("24")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h4",{attrs:{id:"columnname"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#columnname","aria-hidden":"true"}},[t._v("#")]),t._v(" columnName")]),t._v(" "),a("p",[t._v("Inside an attribute definition, you can specify a "),a("code",[t._v("columnName")]),t._v(" to force Waterline to store data\nfor that attribute in a specific column in the configured connection.\nBe aware that this is not necessarily SQL-specific. It will also work for MongoDB fields, etc.")]),t._v(" "),a("p",[t._v("While the "),a("code",[t._v("columnName")]),t._v(" property is primarily designed for working with existing/legacy databases,\nit can also be useful in situations where your database is being shared by other applications,\nor you don't have access permissions to change the schema.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"name"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"columnName"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"pet_name"')]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h2",{attrs:{id:"associations"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#associations","aria-hidden":"true"}},[t._v("#")]),t._v(" Associations")]),t._v(" "),a("p",[t._v("With Waterline you can associate models with other models across all data stores.\nThis means that your users can live in PostgreSQL and their photos can live in MongoDB\nand you can interact with the data as if they lived together on the same database.\nYou can also have associations that live on separate connections or in different databases\nwithin the same adapter.")]),t._v(" "),a("h3",{attrs:{id:"one-way-associations"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#one-way-associations","aria-hidden":"true"}},[t._v("#")]),t._v(" One-Way associations")]),t._v(" "),a("p",[t._v("A one-way association is where a model is associated with another model.\nYou could query that model and populate to get the associated model.\nYou can't however query the associated model and populate to get the associating model.")]),t._v(" "),a("p",[t._v("In this example, we are associating a "),a("code",[t._v("User")]),t._v(" with a "),a("code",[t._v("Pet")]),t._v(" but not a "),a("code",[t._v("Pet")]),t._v(" with a "),a("code",[t._v("User")]),t._v(".\nBecause we have only formed an association on one of the models, a "),a("code",[t._v("Pet")]),t._v(" has no restrictions\non the number of "),a("code",[t._v("User")]),t._v(" models it can belong to. If we wanted to, we could change this and\nassociate the "),a("code",[t._v("Pet")]),t._v(" with exactly one "),a("code",[t._v("User")]),t._v(" and the "),a("code",[t._v("User")]),t._v(" with exactly one "),a("code",[t._v("Pet")]),t._v(".")]),t._v(" "),a("p",[a("code",[t._v("./api/pet/models/Pet.settings.json")]),t._v(":")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"name"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"unique"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"color"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("p",[a("code",[t._v("./api/user/models/User.settings.json")]),t._v(":")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"name"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"unique"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"color"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"pony"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"model"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"pet"')]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h3",{attrs:{id:"one-to-one-associations"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#one-to-one-associations","aria-hidden":"true"}},[t._v("#")]),t._v(" One-to-One associations")]),t._v(" "),a("p",[t._v("A one-to-one association states that a model may only be associated with one other model.\nIn order for the model to know which other model it is associated with a foreign key must\nbe included in the record.")]),t._v(" "),a("p",[t._v("In this example, we are associating a "),a("code",[t._v("Pet")]),t._v(" with a "),a("code",[t._v("User")]),t._v(". The "),a("code",[t._v("User")]),t._v(" may only have one\n"),a("code",[t._v("Pet")]),t._v(" and viceversa, a "),a("code",[t._v("Pet")]),t._v(" can only have one "),a("code",[t._v("User")]),t._v(". However, in order to query this association\nfrom both sides, you will have to create/update both models.")]),t._v(" "),a("p",[a("code",[t._v("./api/pet/models/Pet.settings.json")]),t._v(":")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"name"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"unique"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"color"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"owner"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"model"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"user"')]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("p",[a("code",[t._v("./api/user/models/User.settings.json")]),t._v(":")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"name"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"unique"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"age"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"integer"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"pony"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"model"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"pet"')]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h3",{attrs:{id:"one-to-many-associations"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#one-to-many-associations","aria-hidden":"true"}},[t._v("#")]),t._v(" One-to-Many associations")]),t._v(" "),a("p",[t._v("A one-to-many association states that a model can be associated with many other models.\nTo build this association a virtual attribute is added to a model using the "),a("code",[t._v("collection")]),t._v(" property.\nIn a one-to-many association one side must have a "),a("code",[t._v("collection")]),t._v(" attribute and the other side must contain a\n"),a("code",[t._v("model")]),t._v(" attribute. This allows the many side to know which records it needs to get when a "),a("code",[t._v("populate")]),t._v(" is used.")]),t._v(" "),a("p",[t._v("Because you may want a model to have multiple one-to-many associations on another model a "),a("code",[t._v("via")]),t._v(" key is\nneeded on the "),a("code",[t._v("collection")]),t._v(" attribute. This states which "),a("code",[t._v("model")]),t._v(" attribute on the one side of the association\nis used to populate the records.")]),t._v(" "),a("p",[t._v("In this example, a "),a("code",[t._v("User")]),t._v(" can have several "),a("code",[t._v("Pet")]),t._v(", but a "),a("code",[t._v("Pet")]),t._v(" has only one "),a("code",[t._v("owner")]),t._v(" (from the "),a("code",[t._v("User")]),t._v(" model).")]),t._v(" "),a("p",[a("code",[t._v("./api/pet/models/Pet.settings.json")]),t._v(":")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"name"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"unique"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"color"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"owner"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"model"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"user"')]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("p",[a("code",[t._v("./api/user/models/User.settings.json")]),t._v(":")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"name"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"unique"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"age"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"integer"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"pets"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"collection"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"pet"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"via"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"owner"')]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h3",{attrs:{id:"many-to-many-associations"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#many-to-many-associations","aria-hidden":"true"}},[t._v("#")]),t._v(" Many-to-Many associations")]),t._v(" "),a("p",[t._v("A many-to-many association states that a model can be associated with many other models\nand vice-versa. Because both models can have many related models a new join table will\nneed to be created to keep track of these relations.")]),t._v(" "),a("p",[t._v("Waterline will look at your models and if it finds that two models both have "),a("code",[t._v("collection")]),t._v("\nattributes that point to each other, it will automatically build up a join table for you.")]),t._v(" "),a("p",[t._v("Because you may want a model to have multiple many-to-many associations on another model\na "),a("code",[t._v("via")]),t._v(" key is needed on the "),a("code",[t._v("collection")]),t._v(" attribute. This states which "),a("code",[t._v("model")]),t._v(" attribute on the\none side of the association is used to populate the records.")]),t._v(" "),a("p",[t._v("Using the "),a("code",[t._v("User")]),t._v(" and "),a("code",[t._v("Pet")]),t._v(" example lets look at how to build a schema where a "),a("code",[t._v("User")]),t._v(" may\nhave many "),a("code",[t._v("Pet")]),t._v(" records and a "),a("code",[t._v("Pet")]),t._v(" may have multiple owners.")]),t._v(" "),a("p",[t._v("In this example, we will start with an array of users and an array of pets.\nWe will create records for each element in each array then associate all of the "),a("code",[t._v("Pets")]),t._v(" with all\nof the "),a("code",[t._v("Users")]),t._v(". If everything worked properly, we should be able to query any "),a("code",[t._v("User")]),t._v(" and see that\nthey "),a("em",[t._v("own")]),t._v(" all of the "),a("code",[t._v("Pets")]),t._v(". Furthermore, we should be able to query any "),a("code",[t._v("Pet")]),t._v(" and see that\nit is "),a("em",[t._v("owned")]),t._v(" by every "),a("code",[t._v("User")]),t._v(".")]),t._v(" "),a("p",[a("code",[t._v("./api/pet/models/Pet.settings.json")]),t._v(":")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"name"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"unique"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"color"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"owners"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"collection"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"user"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"via"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"pets"')]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("p",[a("code",[t._v("./api/user/models/User.settings.json")]),t._v(":")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"attributes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"name"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"string"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"unique"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"age"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"type"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"integer"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"required"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"pets"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"collection"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"pet"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"via"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"owners"')]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("h2",{attrs:{id:"lifecycle-callbacks"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#lifecycle-callbacks","aria-hidden":"true"}},[t._v("#")]),t._v(" Lifecycle Callbacks")]),t._v(" "),a("p",[t._v("Lifecycle callbacks are functions you can define to run at certain times in a query.\nThey are hooks that you can tap into in order to change data.")]),t._v(" "),a("p",[t._v("Strapi exposes a handful of lifecycle callbacks by default.")]),t._v(" "),a("h3",{attrs:{id:"callbacks-on-create"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#callbacks-on-create","aria-hidden":"true"}},[t._v("#")]),t._v(" Callbacks on create")]),t._v(" "),a("ul",[a("li",[a("code",[t._v("beforeValidate")]),t._v(": "),a("code",[t._v("fn(values, cb)")])]),t._v(" "),a("li",[a("code",[t._v("afterValidate")]),t._v(": "),a("code",[t._v("fn(values, cb)")])]),t._v(" "),a("li",[a("code",[t._v("beforeCreate")]),t._v(": "),a("code",[t._v("fn(values, cb)")])]),t._v(" "),a("li",[a("code",[t._v("afterCreate")]),t._v(": "),a("code",[t._v("fn(newlyInsertedRecord, cb)")])])]),t._v(" "),a("h3",{attrs:{id:"callbacks-on-update"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#callbacks-on-update","aria-hidden":"true"}},[t._v("#")]),t._v(" Callbacks on update")]),t._v(" "),a("ul",[a("li",[a("code",[t._v("beforeValidate: fn(valuesToUpdate, cb)")])]),t._v(" "),a("li",[a("code",[t._v("afterValidate: fn(valuesToUpdate, cb)")])]),t._v(" "),a("li",[a("code",[t._v("beforeUpdate: fn(valuesToUpdate, cb)")])]),t._v(" "),a("li",[a("code",[t._v("afterUpdate: fn(updatedRecord, cb)")])])]),t._v(" "),a("h3",{attrs:{id:"callbacks-on-destroy"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#callbacks-on-destroy","aria-hidden":"true"}},[t._v("#")]),t._v(" Callbacks on destroy")]),t._v(" "),a("ul",[a("li",[a("code",[t._v("beforeDestroy")]),t._v(": "),a("code",[t._v("fn(criteria, cb)")])]),t._v(" "),a("li",[a("code",[t._v("afterDestroy")]),t._v(": "),a("code",[t._v("fn(deletedRecord, cb)")])])]),t._v(" "),a("p",[t._v("For example, this could be your "),a("code",[t._v("./api/pet/models/Pet.js")]),t._v(" file:")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("module"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("exports "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token comment"}},[t._v("/**\n * Basic settings\n */")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("// The identity to use.")]),t._v("\n identity"),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" settings"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("identity"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("// The connection to use.")]),t._v("\n connection"),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" settings"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("connection"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("// Do you want to respect schema?")]),t._v("\n schema"),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" settings"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("schema"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("// Merge simple attributes from settings with those ones.")]),t._v("\n attributes"),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" _"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("merge")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("settings"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("attributes"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("// Do you automatically want to have time data?")]),t._v("\n autoCreatedAt"),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" settings"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("autoCreatedAt"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n autoUpdatedAt"),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" settings"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("autoUpdatedAt"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("/**\n * Lifecycle callbacks on create\n */")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("// Before creating a value.")]),t._v("\n beforeCreate"),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("values"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" next"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token comment"}},[t._v("// Do some stuff")]),t._v("\n "),a("span",{attrs:{class:"token function"}},[t._v("next")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("// After creating a value.")]),t._v("\n afterCreate"),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("newlyInsertedRecord"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" next"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token comment"}},[t._v("// Do some stuff")]),t._v("\n "),a("span",{attrs:{class:"token function"}},[t._v("next")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("/**\n * Lifecycle callbacks on update\n */")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("// Before updating a value.")]),t._v("\n beforeUpdate"),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("valuesToUpdate"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" next"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token comment"}},[t._v("// Do some stuff")]),t._v("\n "),a("span",{attrs:{class:"token function"}},[t._v("next")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("// After updating a value.")]),t._v("\n afterUpdate"),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("updatedRecord"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" next"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token comment"}},[t._v("// Do some stuff")]),t._v("\n "),a("span",{attrs:{class:"token function"}},[t._v("next")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("/**\n * Lifecycle callbacks on destroy\n */")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("// Before destroying a value.")]),t._v("\n beforeDestroy"),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("criteria"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" next"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token comment"}},[t._v("// Do some stuff")]),t._v("\n "),a("span",{attrs:{class:"token function"}},[t._v("next")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\n "),a("span",{attrs:{class:"token comment"}},[t._v("// After destroying a value.")]),t._v("\n afterDestroy"),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("destroyedRecords"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" next"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token comment"}},[t._v("// Do some stuff")]),t._v("\n "),a("span",{attrs:{class:"token function"}},[t._v("next")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])])}],!1,null,null,null);e.options.__file="models.md";s.default=e.exports}}]);