Tag: 模型

Mongoose DBRef删除原始模式删除删除DBRefs并从DBRefarrays拉出

在mongoose中 , 我可以声明模式 ,也可以使用 DBREF 这只是把ObjectId或一个ObjectId的数组 并填充(获取)这些项目。 我认为这将是一个DBRef删除需要时的问题。 有什么办法可能同步去除DBref ? 例如 从数组中删除 DBRef应该删除其他集合中的DBRef的DBRef,并从 DBRef的数组中取出 DBRef在不同的集合中 从文档的Schema中删除一个文档(DBRef)也会删除其他集合中的DBRef的文档,并且从不同集合中的DBRef数组中提取 DBRef 这些可能吗? 如果是这样, 我怎么能实现这些 ? 或者其他的模型devisebuild议 ?

我如何使用Geddy Model Events?

我是geddy的新手,我对如何使用模型事件感到困惑。 我的模型有一个slug字段,我想在保存任何logging之前生成slug(基于它们input的名字)。 换句话说,我该怎么做geddy? 导轨模型: before_save :generateSlug private: def generateSlug self.slug = self.name.parameterize end 示例模型代码:model / page.js slugify = require('slug'); var Page = function(){ this.defineProperties({ slug: {type: 'string'}, name: {type: 'string', required: true} }); this.beforeSave = function(){ this.slug = slugify(this.name); } } exports.Page = Page; 当我运行p = geddy.model.Page.create({name: 'hello world'}); 和p.save(function(e,d){ console.log(d); }) slug是未定义的

Sails.js的模型是否具有反向引用能力,如Django中的模型。

我对sails.js很陌生。 在使用Django Web框架之前,我有一些经验。 django非常漂亮的function之一是它的模型的反向引用能力..我想知道在sails.js中是否有这样的事情..?

支持ORM中的MySQL视图支持

我想在我正在构build的Web应用程序中使用续集作为我的ORM。 该应用程序将基于NodeJS – Express构build和MySQL作为其关系数据库。 我在documentaino或网上找不到任何地方,是如何在后续模型中声明存在于我的MySQL数据库中的“视图”…. 是手动构build查询SQL的唯一方法吗? 谢谢

Sails中的模型的独特属性

我是SAILS的新手。 我有以下型号。 型号\ Company.js module.exports = { attributes: { name: { type: 'string', required: true, unique: true }, description: { type: 'string', required: true } } }; 型号\ Project.js module.exports = { attributes: { name: { type: 'string', required: true }, key: { type: 'string', required: true, unique: true }, description: { type: 'string' }, […]

SLC Loopback:使用模型钩子中的模型实例

使用loopback模型钩子,我知道你可以通过使用beforeCreate创build一个像User一样的模型实例。 User.beforeCreate = function(next, userInstance) { //your logic goes here using userInstance next(); }; 但是,如果我需要添加一些使用刚创build的用户的firstName的应用程序逻辑,我该怎么做呢? User.afterCreate = function(next) { //I need access to the user that was just created and some of it's properties next(); }; 有没有一种方法来获得刚刚创build的用户,还是需要更改我的应用程序逻辑以使用之前而不是之后?

如何将模型方法添加到用户会话?

我有一个User模型,我在Sails.js中使用Passport.js 。 通过这个设置, req.user返回当前用户会话的详细信息,如req.user.username返回“Jimmy”,用于Jimmy的会话。 我觉得这非常方便布局的目的,我也想添加一个方法,find用户设置,可通过req.user 。 到目前为止,我的方法(在User模型中)看起来像这样: getSetting: function(code) { UserSettings.find({ where: { user: req.user.id, code: code } }).exec(function(err, setting) { return setting.value; }); } 我怎样才能使这个方法可以通过req.user ,以便当我做req.user.getSetting('TEST_CODE'); 我得到了那个用户所需的设置值? 否则,我怎样才能轻松访问用户的设置? 我有一个与User模型关联的UserSettings模型。 编辑: 用户模型我有: var User = { schema: true, attributes: { username : { type: 'string', unique: true }, email : { type: 'email', unique: true […]

强循环(loopback)类方法

理解Strongloop模型的行为有些困难。 有很多关于静态和远程方法的文档,但是一般的类方法呢? 比方说,我有一个用户模型,它有一个显示全名的方法: module.exports = function (User) { User.name = function () { return User.firstname + ' ' + User.lastname; } }; 我如何获取这个用户并使用这个方法? 我会想: var User = app.models.User; User.findById('559103d66d', function (err, model) { console.log(model.name()); }); 但显然,findById返回一个包含所有属性而不是实际模型的JSON对象。 那么如何在Strongloop中定义和使用模型方法呢?

MongoDB:多个填充子文档不被返回

我正在尝试返回文档和子文档的完整数据对象。 它返回的是文档和子文档的ObjectID。 我已经尝试了多个填充语句,这也是行不通的。 我错过了什么? 用户架构 module.exports = function (connection) { var mongoose = require('mongoose'); var Schema = mongoose.Schema; var user_fb = new mongoose.Schema({ name: String, location: String, fb_id: Number, fb_image: String }); return connection.model('User_Fb', user_fb);; } Feed架构 module.exports = function (connection) { var mongoose = require('mongoose'); var Schema = mongoose.Schema; var locationSchema = new Schema({ […]

将.exec(err,rows)中的MySQL行返回给Sails JS中的一个函数(我不想在响应中发送行)

如果我不想通过response.json()的response.ok()将它发送给响应,我如何返回表(模型)的行。 我有user模型的API /模型/ User.js module.exports = { attributes: { name:{ type:'string' }, age:{ type:'text' } } }; 我正在写一个函数在api / services / sendList.js module.exports=function sendList(model){ model.find({}).exec(function(err,rows){ //here i dont want to send it as res.json(rows) }); /***i want to return the rows obtained so that it can be used *somewhere else(wherever the function **sendList** is being […]