Skip to content

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

Merged
sdepold merged 2 commits intosequelize:masterfrom
duhruh:master
Sep 20, 2013
Merged

sequelize.import can now accept a function or a path as the definition#911
sdepold merged 2 commits intosequelize:masterfrom
duhruh:master

Conversation

@duhruh
Copy link
Copy Markdown
Contributor

@duhruh 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){ ... }
exports.name = "Post"
exports.foo = "bar"

// in app.js
var obj = require('./models/post.js')
sequelize.import(obj.name, 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")

@sdepold
Copy link
Copy Markdown
Member

sdepold commented Sep 20, 2013

can you please add a test for that?

@sdepold sdepold merged commit 4a90430 into sequelize:master Sep 20, 2013
@sdepold
Copy link
Copy Markdown
Member

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants