1
votes

I am using sails-hook-sequelize to load sequelize as the ORM in my sails app. However, my controllers and policies setup (i.e. just creating their methods) is dependent on the models. I need to run the sails-hook-sequelize installable hook before I run controllers and policies hooks (currently it is running it after and the controllers/policies are failing to load). How can I do this? T

Thanks in advance.

Edit: Here is some code to illustrate what I am trying to accomplish:

UserController.js

let Endpoint = require('../classes/Endpoint');

let endpoint = new Endpoint(User);

Object.assign(endpoint, {
    find
});

module.exports = endpoint;

function find(req, res, next) {
    User.findAll(
        {
            where: req.query,
            include: [
                {
                    model: Privilege,
                    include: [
                        {
                            model: Account,
                            where: {
                                accountPkey: {
                                    $in: AuthorizationService.accountsForPrivileges(req.tokenData.privileges, ['ADMINISTRATOR', 'OFFICE MANAGER'])
                                }
                            }
                        }
                    ]
                }
            ]
        })
        .then(users => res.ok(users))
        .catch(err => res.serverError(err));
}

basically, I have a default Endpoint class that I instantiate and then add methods to. You can see that the Endpoint class takes a model argument. However, when this hook runs, the models don't exist yet because they are defined by a third party hook (using sequelize).

1

1 Answers

0
votes

There's currently no way to run a third-party hook before the core hooks in Sails.

Often times when I see questions like this, it's from someone who's trying to create a Wordpress-like platform, and they're making the assumption that for every new "entity type" that an end-user creates (i.e. blog, article, comment) they need a new model. An alternative is to create an Entity model, with a contents attribute that is an association to a Content or EntityAttribute model which is more or less just a key/value store. Then you can use wildcard routes to have the EntityController actions load the correct type of entity.