nocobase/docs/zh-CN/welcome/release/inherits.md
ChengLei Shao e991b2965a
feat: collection inheritance (#1069)
* chore: test

* chore: inherited-collection class

* feat: collection inherit

* feat: collection inherit

* feat: inhertis sync runner

* test: get parents fields

* feat: collection inherit style promote

* feat: sync

* feat: sync alter table

* feat: pgOnly Test

* fix: child collection create api

* feat: replace parent field

* chore: reload parent fields

* test: reload collection test

* feat: details are displayed according to conditions

* fix: typo

* feat: inheritance map class

* chore: is parent node

* feat: display where child row created from

* fix: find with appends

* feat: add parent collection fields

* fix: create table

* feat: load fields for all children

* refactor: sync fields from parent

* test: has one field inhertis

* feat: replace child association target

* feat: should not replace child field when parent field update

* test: should update inherit field when parent field update

* feat: only the blocks directly inherited from the current data are displayed

* fix: inherit from multiple collections

* feat: only the blocks directly inherited from the current data are displayed

* fix: test

* feat: parent collection expend

* fix: test

* test: belongsToMany inherits

* test: belongsToMany inherits

* feat: block display

* feat: collection inherite

* feat: collection inherite

* feat: multiple inherits

* fix: sync runner

* feat: collection inherite

* feat: collecton inherits

* feat: cannot be modified after inheritance and saving

* feat: collection inherit for graph

* feat: collection inherits

* fix: drop inhertied field

* fix: should throw error when type conflit

* feat: output inherited fields

* feat: bulk update collection fields

* feat: collection fields

* feat: collection fields

* test: create relation with child table

* fix: test

* fix: test

* fix: test

* feat: style impove

* test: should not replace field with difference type

* feat: add text

* fix: throw error when replace field with difference type

* feat: overriding

* feat: kan bankanban group fields

* feat: calendar block fields

* feat: kan bankanban group fields

* fix: test

* feat: relationship fields

* feat: should delete child's field when parent field deleted

* feat: foreign key filter

* fix: build error & multiple inherit destory field

* fix: test

* chore: disable error

* feat: no recursive update associations (#1091)

* feat: update associations

* fix(collection-manager): should update uiSchema

* chore: flip if

* feat: mutile inherits

* feat: db dialect

* feat: inherits show by database

* chore: git hash into docker image

* fix: js gzip

* fix: dockerfile

* chore: error message

* feat: overriding

* feat: overriding

* feat: overriding

* feat: local

* feat: filter fields by interface

* fix: database logging env

* test: replace hasOne target

* feat: add view

* feat: local

* chore: enable error

* fix: update docs

Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2022-11-16 12:53:58 +08:00

2.0 KiB
Raw Blame History

v0.8.1: 数据表继承

数据表继承基于 PostgreSQL 的 INHERITS 语法 实现,仅限于 PostgreSQL 数据库安装的 NocoBase 时才会提供。

示例

我们从一个例子开始,假设要做一个教学系统,有三类用户:学生、家长和老师。

如果没有继承,要分别为三类用户建表:

  • 学生:姓名、年龄、性别、身份证
  • 家长:姓名、年龄、性别、职业、学历
  • 老师:姓名、年龄、性别、教龄、已婚

有了数据表继承之后,共同的信息就可以提炼出来:

  • 用户:姓名、年龄、性别
  • 学生:身份证
  • 家长:职业、学历
  • 老师:教龄、已婚

ER 图如下:

注:子表 ID 和父表 ID 共享序列

配置数据表继承

Inherits 字段选择需要继承的数据表

通过代码配置如下:

db.collection({
  name: 'users',
});

db.collection({
  name: 'students',
  inherits: 'users',
});

注意:

  • 继承的表并不能随意选择,主键必须是唯一序列,比如 uuid 或者所有继承线路上的表的 id 自增序列都用同一个
  • Inherits 参数不能被编辑
  • 如果有继承关系,被继承的父表不能被删除

数据表字段列表

字段列表里同步显示继承的父表字段父表字段不可以修改但可以重写Override

重写父表字段的注意事项:

  • 子表字段标识与父表字段一样时为重写
  • 重写字段的类型必须保持一致
  • 关系字段除了 target collection 以外的其他参数需要保持一致

父表的子表区块

在父表区块里可以配置子表的区块

新增继承的父表字段的配置

当有继承的父表时,配置字段时,会提供从父表继承的字段的配置