0

I created model Pattern.js, looks this way:

var Pattern = {

  adapter: 'land',

  attributes: {
    name: 'STRING',
    code: 'STRING'
  }
};

module.exports = Pattern;

And now I have two problems:

  1. I can't get access from my HomeController to this model. I tried to require it, but code fails. How to get access to the models from other files?
  2. There is no method 'create' in the documentation, so what is the way to create new record using a defined model?

1 Answer 1

2

Accessing models

You do not have to require the model yourself, Sails does this for you.

Every model you define is available in the global scope as Filename (uppercase first letter) and in sails.models.filename (all lowercase) by default after the orm hook has run.

sails is available in the global scope too.

Documentation

I do not know wich docs you refer to, but there is a create method available on Sails / Waterline models. In your example:

Pattern.create(data).exec(callback);

You can look up on Sails / Waterline models here:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.