【文件属性】:
文件名称:关于Sequelize连接查询时inlude中model和association的区别详解
文件大小:46KB
文件格式:PDF
更新时间:2021-01-20 07:38:51
AS c ci
前言
大家都知道在使用Sequelize进行关系模型(表)间连接查询时,我们会通过model/as来指定已存在关联关系的连接查询模型,或是通过association来直接指定连接查询模型关系。那么,两者各应该在什么场景下使用呢?
一、 示例准备
模型定义
首先,定义User和Company两个模型:
'use strict'
const Sequelize = require('sequelize');
// 创建 sequelize 实例
const sequelize = new Sequelize('db1', 'root', '111111', {logging: console.