bun*_*unt 8 javascript node.js express sails.js
从sails.js例子来看,
// Person.js
var Person = {
attributes: {
firstName: 'STRING',
lastName: 'STRING',
age: {
type: 'INTEGER',
max: 150,
required: true
}
birthDate: 'DATE',
phoneNumber: {
type: 'STRING',
defaultsTo: '111-222-3333'
}
emailAddress: {
type: 'email', // Email type will get validated by the ORM
required: true
}
}
};
Run Code Online (Sandbox Code Playgroud)
现在我如何添加emailAddress以将家庭和办公室作为嵌入字段?
试图这样做:
emailAddress: { {
work: {
type: 'email',
},
personal: {
type: 'email',
}
}
},
Run Code Online (Sandbox Code Playgroud)
和
emailAddress: {
attributes: {
work: {
type: 'email',
},
personal: {
type: 'email',
}
}
},
Run Code Online (Sandbox Code Playgroud)
两者都不起作用.我得到的错误如第二种情况"找不到属性的规则",第一种情况下的"意外的令牌{".
bun*_*unt 10
好的,通过一些线程来解决这个问题.在这个阶段,似乎Sails Waterline不支持嵌入式MongoDB架构.您可以编写自己的贡献或强制它,但是开箱即用支持(模型验证)等也需要被黑客攻击. https://github.com/balderdashy/sails-mongo/issues/44
另一个选择 - sails-mongoose遗憾的是也不受支持. 我们可以在node.js + sailsjs中从哪里决定使用"sails-mongoose"包的集合名称?
更新.从V0.10开始,Sails支持关联.也许这会使它发挥作用.还在试验中.
更新.使用关联功能,您可以在不同的模型中强制使用模式并在它们之间创建引用,但到目前为止,您似乎无法嵌入它们 - 只能将它们与不同的集合/表相关联.