数据模型内置了更新处理器, 这些处理器可用于服务接口(API
)和数据流(Flow
)数据更新功能。
models/category.mod.json
文件,写入以下内容:{"name": "书籍分类","table": {"name": "category","comment": "书籍分类"},"columns": [{"label": "ID","name": "id","type": "ID","comment": "ID","primary": true},{"label": "父级id","name": "parent_id","type": "integer","nullable": true},{"label": "分类名称","name": "name","type": "string","length": 128,"index": true}],"relations": {"book": {"type": "hasMany","model": "book","key": "category_id","foreign": "id","query": {}},"parent": {"type": "hasOne","model": "category","key": "id","foreign": "parent_id","query": {}}},"option": {"timestamps": true,"soft_deletes": true},"values": [{"id": 1,"parent_id": null,"name": "文史类"},{"id": 2,"parent_id": 1,"name": "历史"},{"id": 3,"parent_id": 1,"name": "古诗"},{"id": 4,"parent_id": null,"name": "理工类"},{"id": 5,"parent_id": 4,"name": "数学"},{"id": 6,"parent_id": 4,"name": "物理"}]}
scripts/test.js
function Save() {return Process("models.category.save", {id: 6,parent_id: 1,name: "语文",});}
function Update() {return Process("models.category.update", 9, {parent_id: 1,name: "英语",});}
function UpdateWhere() {return Process("models.category.updatewhere",{wheres: [{ column: "parent_id", value: 1 }],},{name: "数学",});}
执行 yao run scripts.test.Save
和yao run scripts.test.UpdateWhere
和yao run scripts.test.Update
数据模型内置了更新处理器, 这些处理器可用于服务接口(API
)和数据流(Flow
)数据更新功能。
models/category.mod.json
文件,写入以下内容:{"name": "书籍分类","table": {"name": "category","comment": "书籍分类"},"columns": [{"label": "ID","name": "id","type": "ID","comment": "ID","primary": true},{"label": "父级id","name": "parent_id","type": "integer","nullable": true},{"label": "分类名称","name": "name","type": "string","length": 128,"index": true}],"relations": {"book": {"type": "hasMany","model": "book","key": "category_id","foreign": "id","query": {}},"parent": {"type": "hasOne","model": "category","key": "id","foreign": "parent_id","query": {}}},"option": {"timestamps": true,"soft_deletes": true},"values": [{"id": 1,"parent_id": null,"name": "文史类"},{"id": 2,"parent_id": 1,"name": "历史"},{"id": 3,"parent_id": 1,"name": "古诗"},{"id": 4,"parent_id": null,"name": "理工类"},{"id": 5,"parent_id": 4,"name": "数学"},{"id": 6,"parent_id": 4,"name": "物理"}]}
scripts/test.js
function Save() {return Process("models.category.save", {id: 6,parent_id: 1,name: "语文",});}
function Update() {return Process("models.category.update", 9, {parent_id: 1,name: "英语",});}
function UpdateWhere() {return Process("models.category.updatewhere",{wheres: [{ column: "parent_id", value: 1 }],},{name: "数学",});}
执行 yao run scripts.test.Save
和yao run scripts.test.UpdateWhere
和yao run scripts.test.Update