如何在 sails.js 中查看完整的相关模型?

How can i get the full related model in view in sails.js?

我创建了一个 sails.js 应用程序。

我正在尝试查看完整的相关模型 Creator,但我只得到 ID...

我该怎么做?

我正在这样做:

型号Author.js

    module.exports = {

        attributes: {
            name: {
                type: 'string',
                required: true
            },
            description: {
                type: 'string'
            },
            history: {
                type: 'string'
            },

            creator: {
                model: 'User'
            }
        }
    };

型号User.js

    module.exports = {


    attributes: {
        name: {
            type: 'string',
            required: true
        },
        email: {
            type: 'string',
            email: true,
            required: true,
            unique: true
        }
        authors: {
            collection: 'Author',
            via: 'creator'
        },
...
    }
};

作者控制器:

show: function(req, res, next) {
        Author.findOne(req.param('id'), function foundAuthor(err, author) {
            console.log(author.creator);
            res.view({
                author: author,
            });
        });

    }

在我看来 author/show.ejs

<div class="container">

    <h1><%= author.name %></h1>
    <h3><%= author.creator %></h3>
    <h3><%= author.creator.name %></h3>


</div>

author.creator.name 未定义 author.creator 是 id

如何在作者视图中获取完整模型用户而不是 id?

你需要告诉 sails 来填充创建者

show: function(req, res, next) {
        Author.findOne(req.param('id').populate('creator').exec(function foundAuthor(err, author) {
            console.log(author.creator);
            res.view({
                author: author,
            });
        });
    }