New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sequelize.import can now accept a function or a path as the definition #911

merged 2 commits into from Sep 20, 2013


2 participants

duhruh commented Sep 16, 2013

Before, the import function required a path to a model definition file. This limited the ability to structure an application and define other attributes about the model (possibly outside the scope of sequelize) in the same file, e.g. model associations. Now this is possible:

sequelize.import('Posts', function(sequelize, DataTypes) {
    return sequelize.define("Posts", {
        name: DataTypes.STRING,
        description: DataTypes.TEXT

or this

// in model/posts.js
exports.definition = function(sequelize, DataTypes){ ... } = "Post" = "bar"

// in app.js
var obj = require('./models/post.js')
sequelize.import(, obj.definition);

This still allows for the ability to cache imports and, for backwards compatibility, to pass a path to import:

sequelize.import(__dirname + "/path/to/models/project")

This comment has been minimized.


sdepold commented Sep 20, 2013

can you please add a test for that?

@sdepold sdepold merged commit 4a90430 into sequelize:master Sep 20, 2013


This comment has been minimized.


sdepold commented Sep 20, 2013

Thanks a lot :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment