strapi/docs/.vuepress/dist/assets/js/16.5c84c402.js

1 line
78 KiB
JavaScript
Raw Normal View History

2018-10-05 17:24:17 +02:00
(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("s