簡體   English   中英

如何在 SailsJS 中創建與另一個模型的對象單向關聯的對象列表?

[英]How to create a list of objects which are one-way associated with objects of another model in SailsJS?

我有模型Playlist.jsUser.js 我想在播放列表中有一個用戶列表,他們可以回答對他們的評論。 我不希望該屬性出現在用戶中。 (即單向關聯)

播放列表.js

module.exports = {
    attributes: {
        id: {
            type: 'integer',
            autoIncrement: true,
            primaryKey: 
        },        
        name: {
            type: 'string',
            size: 128,
            required: true
        },
        // many to many relationship with role
        roles_with_access: {
            collection: 'role',
            via: 'playlist',
            through: 'rolehasplaylist'
        },

        // THIS ATTRIBUTE ASSOCIATE WITH ONE USER
        // BUT INSTEAD OF THAT I WANT A LIST OF USERS
        users_who_can_answer_comments: {
            model: 'user'
        }
    }
};

用戶.js

module.exports = {
    attributes: {
        id: {
            type: 'integer',
            autoIncrement: true,
            primaryKey: true,
        },
        name: {
            type: 'string',
            size: 128,
            required: true
        },
        email: {
            type: 'email',
            required: true,
            unique: true
        },
        adminRole: {
            model: 'role'
        }
    }
};

Sails 文檔提到單向關聯僅用於一對一映射 - http://sailsjs.org/documentation/concepts/models-and-orm/associations/one-way-association我想找到一種方法與用戶關聯的用戶列表?

將模型更改為集合:

users_who_can_answer_comments: {
    collection: 'user'
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM