Kadosh
Kadosh

Reputation: 319

sails.js waterline model not working

I have the next two models:

module.exports = {
    identity: 'WebsiteWidget',
    attributes: {
        name: 'string',
        type: {
          type: 'string',
          enum: ['fullPage', 'container', 'base']
        },
        container: {
          model: 'container'
        },
        widget: {
          model: 'widget'
        },
        page: {
          model: 'page'
        },
        data: {
          type: 'json'
        },
        output: {
          type: 'text'
        },
        widgetHtml: {
            model: 'widgethtml'
        },
        sort: 'integer'
    }
}

module.exports = {
    attributes: {
        widget: 'string',
        templateName: 'string',
        source: 'text',
        settings: 'json'
    }
};

The thing is that WebsiteWidget holds an id of WidgetHtml, when i execute a find query, the websiteHtml property returns just the id instead of the whole WidgetHtml model. What is the problem?

Upvotes: 3

Views: 638

Answers (2)

bmustata
bmustata

Reputation: 597

Use populate() or populateAll() from Sails.js Waterline.

Upvotes: 0

jaumard
jaumard

Reputation: 8292

You need to explicitly tell waterline to retrieve your WidgetHtml like :

WebsiteWidget.find(....).populate("widgetHtml").exec(function(err, website))
{

//Do what you want 

});

Upvotes: 2

Related Questions