- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在努力更好地了解如何在 SailsJS 中设置外键。我目前正在开展一个类(class)项目,我的小组需要创建一个评估系统,其中包含教师和学生的个人资料以查看结果。我在网上看到了一些例子,但我看到了不同的格式,我不确定正确的格式应该是什么样子。
用户模型
/**
* User.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
attributes: {
// The user's anonymous ID (e.g. 1)
anonymousID: {
type: 'integer',
autoIncrement: true
},
// The user's first name (e.g. Bob)
firstName: {
type: 'string',
required: true
},
//The user's last name (e.g. Smith)
lastName: {
type: 'string',
required: true,
},
// The user's full name (e.g. Bob Smith)
fullName: {
type: 'string',
required: true
},
// The user's assigned NetID (e.g. abc123)
netID: {
type: 'string',
primaryKey: true,
required: true,
unique: true
},
// The user's nine digit SchoolID (e.g. 000-000-000)
schoolID: {
type: 'integer',
size: 9,
required: true,
unique: true
},
// The user's email address (e.g. netID@university.edu)
email: {
type: 'string',
email: true,
required: true,
unique: true
},
// The encrypted password for the user (e.g. asdgh8a249321e9dhgaslcbqn2913051#T(@GHASDGA)
encryptedPassword: {
type: 'string',
required: true
},
// The timestamp when the the user last logged in
// (i.e. sent a username and password to the server)
lastLoggedIn: {
type: 'date',
required: true,
defaultsTo: new Date(0)
},
// The user's academic title (e.g. student)
title: {
state:{
type : 'string',
required: true,
enum: ['Student', 'Faculty', 'Staff', 'Dean'],
defaultsTo: 'Staff'
}
},
// The user's academic classification (e.g. freshman)
classification: {
state: {
type: 'string',
required: true,
enum: ['Freshman', 'Sophomore', 'Junior', 'Senior', 'Graduate', 'N/A']
defaultsTo: 'N/A'
}
},
}
};
调度模型
/**
* Schedule.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
attributes: {
// The CRN ID (e.g. 32458)
courseID: {
type: 'integer',
autoIncrement: true,
primaryKey: true
},
// The Course Reference Name (e.g. MBW 1001)
course: {
type: 'string',
size: 8,
required: true
// Add FK code from Course Table
},
// The Course Name (e.g. Magical Basket Weaving)
title: {
type: 'string',
required: true
// Add FK code from Course Table
},
// The Course Instructor (e.g. ab123)
intructorID: {
type: 'string',
required: true
// Add FK code from User Table
},
// The Term refers to the semester (e.g. Fall 2015)
term: {
type: 'string',
required: true
},
}
};
类(class)模型
/**
* Course.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
attributes: {
// The Evaluation ID (e.g. 1)
courseNum: {
type: 'integer',
autoIncrement: true
},
// The Department Name (e.g. Arts and Sciences)
department: {
type: 'string',
required: true
},
// The Course Reference Name (e.g. MBW 1001)
course: {
type: 'string',
primaryKey: true,
size: 8,
unique: true
},
// The Course Name (e.g. Magical Basket Weaving)
title: {
type: 'string',
required: true
},
}
};
注册模型
/**
* Enrolled.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
attributes: {
// The Transaction ID (e.g. 32458)
transactionID: {
type: 'integer',
autoIncrement: true,
primaryKey: true
},
// The CRN ID (e.g. 32458)
courseID: {
type: 'integer',
required: true
// Add FK code from Schedule Table
},
// The Course Instructor (e.g. ab123)
instructorID: {
type: 'string',
required: true
// Add FK code from Schedule Table
},
// The Course Instructor (e.g. ab123)
studentID: {
type: 'string',
required: true
// Add FK code from User Table
},
// The Term refers to the semester (e.g. Fall 2015)
term: {
type: 'string',
required: true
},
// The Right to Submit an Evaluation (e.g. True or False)
evaluationStatus: {
type: 'boolean',
},
}
};
评价模型
/**
* Evaluation.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
attributes: {
// The Evaluation ID (e.g. 1)
evaluationID: {
type: 'integer',
autoIncrement: true,
primaryKey: true
},
// The user's anonymous ID (e.g. 1)
anonymousID: {
type: 'string',
required: true,
// Add FK code from user table
},
// The Course Instructor (e.g. ab123)
intructorID: {
type: 'string',
required: true
// Add FK code from User Table
},
// The course's assigned CRN (e.g. 12343)
courseID: {
type: 'integer',
required: true,
size: 5
// Add FK code from schedule table
},
// The Course Reference Name (e.g. MBW 1001)
course: {
type: 'string',
size: 8,
},
// The rating of question 1
ratingOne: {
type: 'integer',
required: true,
size: 2
},
// The rating of question 2
ratingTwo: {
type: 'integer',
required: true,
size: 2
},
// The rating of question 3
ratingThree: {
type: 'integer',
required: true,
size: 2
},
// The rating of question 4
ratingFour: {
type: 'integer',
required: true,
size: 2
},
// The rating of question 5
ratingFive: {
type: 'integer',
required: true,
size: 2
},
// The rating of question 6
ratingSix: {
type: 'integer',
required: true,
size: 2
},
// The rating of question 7
ratingSeven: {
type: 'integer',
required: true,
size: 2
},
// The rating of question 8
ratingEight: {
type: 'integer',
required: true,
size: 2
},
// The rating of question 9
ratingNine: {
type: 'integer',
required: true,
size: 2
},
// The rating of question 10
ratingTen: {
type: 'integer',
required: true,
size: 2
},
// The positive feedback from student
positiveFeedback: {
type: 'string',
defaultsTo: 'N/A',
size: 4000
},
// The negative feedback from student
negativeFeedback: {
type: 'string',
defaultsTo: 'N/A',
size: 4000
},
// The General Rating of Evaluation (e.g. 8.76, SUM(ratings)/TotalRatings)
genRateEval: {
type: 'float',
required: true,
size: 4
},
// The Inaproprate Flag (e.g. True or False)
inaproprateFlag: {
type: 'boolean',
},
}
};
我已经包括了我正在使用的所有五个模型,这样每个人都可以全面了解一切将/应该如何连接。
根据我的理解,外键应该像下面的代码片段一样设置。
调度模型(带外键)
/**
* Schedule.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
attributes: {
// The CRN ID (e.g. 32458)
courseID: {
type: 'integer',
autoIncrement: true,
primaryKey: true
},
// The Course Reference Name (e.g. MBW 1001)
course: {
// Add FK code from Course Table
model: 'Course',
via: 'course'
},
// The Course Name (e.g. Magical Basket Weaving)
title: {
// Add FK code from Course Table
model: 'Course',
via: 'title'
},
// The Course Instructor (e.g. ab123)
intructorID: {
// Add FK code from User Table
model: 'User',
via: 'netID'
},
// The Term refers to the semester (e.g. Fall 2015)
term: {
type: 'string',
required: true
},
}
};
不过我不确定这是否是设置外键的正确方法。
最佳答案
是的,这是在 sails js 中设置外键的正确方法。也就是说,它因关联类型而异,即关系是一对一还是一对多。
以sailsjs网站为例,
一对一关系:
myApp/api/models/pet.js
module.exports = {
attributes: {
name:'STRING',
color:'STRING',
owner:{
model:'user'
}
}
}
myApp/api/models/user.js
module.exports = {
attributes: {
name:'STRING',
age:'INTEGER',
pony:{
model: 'pet'
}
}
}
一对多关系:myApp/api/models/pet.js
module.exports = {
attributes: {
name:'STRING',
color:'STRING',
owner:{
model:'user'
}
}
}
myApp/api/models/user.js
module.exports = {
attributes: {
name:'STRING',
age:'INTEGER',
pets:{
collection: 'pet',
via: 'owner'
}
}
}
关于javascript - SailsJS 模型和数据库中的外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34120514/
在 sailsjs 1.0@beta 中,我有一个模型链接到带有 mysql-sails@beta 适配器的 mysql 表中的 View 。 模型配置如下: attributes: { id
我有一个独立的操作,我使用 CloudSDK 通过单击按钮从我的前端调用它,我得到了我的值,但该操作不会重定向到 View 。我已在成功退出中将 responseType 指定为 View ,但这似乎
sails.sockets.rooms()和sails.sockets.socketRooms()均已弃用 在文档中: This method is deprecated. Please keep t
我尝试使用以下方法在 Controller 操作中获取发布数据: req.body.name 但是不起作用 最佳答案 您可以尝试先检索全部内容来访问它们 function(req, res, next
我一直在尝试按照文档和 StackOverflow 上的说明为我的应用程序加载自定义配置,但失败了。 我在中创建了一个新文件 /config/application.js 内容: module.exp
我对两个 Nodejs 和 sails 都很陌生。我正在尝试在一个 Action 中创建两个模型。我的问题是如何处理两个查询中可能发生的错误。 当前代码: new: function (req, re
所以我的问题是我想将任何请求记录到我的 sails 应用程序。基本上我已经解决了一个问题,即我无法记录请求的参数。 myRequestLogger: function(req, res, next)
是否可以动态更新 sails.config 对象,而无需重新升起 sails 来应用这些更改? 我希望动态更新sails.config.policies 在我的 bootstrap.js 中我已经设置
假设我有一个很长的任务,当有人连接到 InitializeDB 时,该任务就开始运行。 (当然,将来会获得授权,但暂时不考虑)。 'post /initializeDB':'OrderControll
问题 所以我正在编辑一个 CRUD 应用程序以在删除之前进行确认,并创建了一个 JavaScript 函数来执行此操作,但我在 cmd 和“显示”页面上收到以下错误 error: Sending 50
我了解到放置在资源中的静态文件将可以直接在浏览器中访问。但是执行此操作后,我的静态文件无法访问。 最后,结果发现静态文件没有编译到隐藏文件夹(.tmp/public)中。我手动将所有文件复制到这个隐藏
sails.js 框架不支持事务。在 GitHub 问题中,他们谈论 transaction()。但是不适合在一个事务中编写多个查询。 所以我认为一种解决方案是使用 node-mysql 模块。但我认
好吧,我(天真地)试图让 bull 在 sails 应用程序中工作:最终我希望有一个队列,我可以根据传入路线向其中添加/删除/检查任务。 现在,据我所知,要创建一个可在全局范围内运行的排队系统,我必须
我正在开发一个 Sails 应用程序,对于我的单元测试,我需要在 ./test/bootstrap.test.js 和 ./test/unit/controllers/*.test.js 中使用一些变
我一直在努力更好地了解如何在 SailsJS 中设置外键。我目前正在开展一个类(class)项目,我的小组需要创建一个评估系统,其中包含教师和学生的个人资料以查看结果。我在网上看到了一些例子,但我看到
我想创建一条动态路线。我创建了一个名为用户的 API。我需要可以访问/users/:nameofuser,就像自动创建的用户/id。 如何在这种类型的 url 中获取用户名,并执行 Controlle
我有一个模型帖子: // Post.js attributes:{ name: {type:"string"}, users: { collection: 'user', via: '
我的 Sailsjs 应用程序中有以下具有多对多关系的模型: 事件.js: attributes: { title : { type: 'string', required: true }, de
我正在使用 Sails v0.10.5。 我创建了三个模型,它们之间存在关联。存在一个Candidate 模型、一个Evaluator 模型和一个Rating 模型,评估者通过该模型对候选人进行评分。
我的 Sails 应用程序中有用户模型,当然它有密码。因此,当我创建新用户时,Sails 会使用包含新创建用户的所有数据(包括哈希密码)的 json 进行响应。有没有办法阻止 Sails 输出某些字段
我是一名优秀的程序员,十分优秀!