Skip to content

Commit

Permalink
sequelize 4 support (#12)
Browse files Browse the repository at this point in the history
* sequelize 4 support

* test with node 6

* add changelog and sequelize as peer dependency

* add changelog and sequelize as peer dependency

* remove changelog
  • Loading branch information
Maxime Suret authored and mickhansen committed Oct 17, 2017
1 parent e1450f6 commit 942cf27
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
language: node_js

node_js:
- "0.10"
- "0.12"
- "iojs"
- 4
- 6

sudo: false

Expand Down
12 changes: 6 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ var Sequelize = require('sequelize')
, init;

init = function(target) {
if (target instanceof Sequelize.Model) {
var $get = target.Instance.prototype.get;
if (target.prototype instanceof Sequelize.Model) {
var $get = target.prototype.get;

Object.keys(target.rawAttributes).forEach(function (attr) {
if (target.rawAttributes[attr].roles !== undefined) {
if (target.rawAttributes[attr].roles === false) {
target.rawAttributes[attr].roles = {};
return;
return;
}

Object.keys(target.rawAttributes[attr].roles).forEach(function (role) {
Expand All @@ -33,7 +33,7 @@ init = function(target) {
}
});

target.Instance.prototype.get = function(key, options) {
target.prototype.get = function(key, options) {
if (typeof key === "object" && !options) {
options = key;
key = undefined;
Expand All @@ -57,12 +57,12 @@ init = function(target) {

var values = $get.call(this, options)
, response = {};

Object.keys(values).forEach(function (key) {
var attr = target.rawAttributes[key];

var val = values[key];
if(!attr && val instanceof Sequelize.Instance) {
if(!attr && val instanceof Sequelize.Model) {
response[key] = val.get.call(val, options);
}
else if (!attr || !attr.roles || attr.roles && attr.roles[options.role] && attr.roles[options.role].get) {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
"istanbul": "^0.3.7",
"jshint": "^2.6.3",
"mocha": "^2.2.1",
"sequelize": "^2.1.1",
"sequelize": "^4.14.0",
"sqlite3": "^3.0.5"
},
"peerDependencies": {
"sequelize": "4.x"
}
}

0 comments on commit 942cf27

Please sign in to comment.