2022-11-07 01:45:44 +00:00
# Collection templates
2022-11-02 03:33:07 +00:00
< Alert >
2022-11-07 01:45:44 +00:00
📢 Collection templates are scheduled to be available in Q4 2022.
2022-11-02 03:33:07 +00:00
< / Alert >
2022-11-07 01:45:44 +00:00
In real business scenarios, different collections may have their own initialization rules and business logic, and NocoBase addresses such issues by providing collection templates.
2022-11-02 03:33:07 +00:00
2022-11-07 01:45:44 +00:00
## General collections
2022-11-02 03:33:07 +00:00
```ts
db.collection({
name: 'posts',
fields: [
{
type: 'string',
name: 'title',
}
],
});
```
2022-11-07 01:45:44 +00:00
## Tree structure collections
2022-11-02 03:33:07 +00:00
```ts
db.collection({
name: 'categories',
tree: 'adjacency-list',
fields: [
{
type: 'string',
name: 'name',
},
{
type: 'string',
name: 'description',
},
{
type: 'belongsTo',
name: 'parent',
target: 'categories',
foreignKey: 'parentId',
},
{
type: 'hasMany',
name: 'children',
target: 'categories',
foreignKey: 'parentId',
},
],
});
```
2022-11-07 01:45:44 +00:00
## Parent-child inheritance collections
2022-11-02 03:33:07 +00:00
```ts
db.collection({
name: 'a',
fields: [
],
});
db.collection({
name: 'b',
inherits: 'a',
fields: [
],
});
```
2022-11-07 01:45:44 +00:00
## More templates
2022-11-02 03:33:07 +00:00
2022-11-07 01:45:44 +00:00
As in the case of calendar collections, each initialized collection needs to be initialized with special cron and exclude fields, and the definition of such fields is done by the template
2022-11-02 03:33:07 +00:00
```ts
db.collection({
name: 'events',
template: 'calendar',
});
```