Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit e739d816
authored
Jan 30, 2016
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update to lodash 4.0 API
1 parent
cdad10ae
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
68 additions
and
56 deletions
lib/associations/belongs-to-many.js
lib/data-types.js
lib/dialects/abstract/connection-manager.js
lib/dialects/abstract/query-generator.js
lib/dialects/mssql/connection-manager.js
lib/dialects/mssql/query.js
lib/dialects/mysql/query.js
lib/dialects/postgres/query-generator.js
lib/instance.js
lib/model.js
lib/utils.js
test/integration/associations/belongs-to-many.test.js
test/integration/associations/scope.test.js
test/integration/query-interface.test.js
test/integration/sequelize.test.js
test/integration/transaction.test.js
lib/associations/belongs-to-many.js
View file @
e739d81
...
@@ -154,7 +154,7 @@ var BelongsToMany = function(source, target, options) {
...
@@ -154,7 +154,7 @@ var BelongsToMany = function(source, target, options) {
this
.
paired
=
association
;
this
.
paired
=
association
;
association
.
paired
=
this
;
association
.
paired
=
this
;
}
}
}
,
this
);
}
.
bind
(
this
)
);
if
(
typeof
this
.
through
.
model
===
'string'
)
{
if
(
typeof
this
.
through
.
model
===
'string'
)
{
if
(
!
this
.
sequelize
.
isDefined
(
this
.
through
.
model
))
{
if
(
!
this
.
sequelize
.
isDefined
(
this
.
through
.
model
))
{
...
@@ -668,7 +668,7 @@ BelongsToMany.prototype.injectSetter = function(obj) {
...
@@ -668,7 +668,7 @@ BelongsToMany.prototype.injectSetter = function(obj) {
var
throughAttributes
=
obj
[
association
.
through
.
model
.
name
]
var
throughAttributes
=
obj
[
association
.
through
.
model
.
name
]
,
attributes
=
_
.
defaults
({},
throughAttributes
,
defaultAttributes
);
,
attributes
=
_
.
defaults
({},
throughAttributes
,
defaultAttributes
);
if
(
_
.
any
(
Object
.
keys
(
attributes
),
function
(
attribute
)
{
if
(
_
.
some
(
Object
.
keys
(
attributes
),
function
(
attribute
)
{
return
attributes
[
attribute
]
!==
existingAssociation
[
attribute
];
return
attributes
[
attribute
]
!==
existingAssociation
[
attribute
];
}))
{
}))
{
changedAssociations
.
push
(
obj
);
changedAssociations
.
push
(
obj
);
...
...
lib/data-types.js
View file @
e739d81
...
@@ -772,7 +772,7 @@ var ENUM = ABSTRACT.inherits(function(value) {
...
@@ -772,7 +772,7 @@ var ENUM = ABSTRACT.inherits(function(value) {
ENUM
.
prototype
.
key
=
ENUM
.
key
=
'ENUM'
;
ENUM
.
prototype
.
key
=
ENUM
.
key
=
'ENUM'
;
ENUM
.
prototype
.
validate
=
function
(
value
)
{
ENUM
.
prototype
.
validate
=
function
(
value
)
{
if
(
!
_
.
contain
s
(
this
.
values
,
value
))
{
if
(
!
_
.
include
s
(
this
.
values
,
value
))
{
throw
new
sequelizeErrors
.
ValidationError
(
util
.
format
(
'%j is not a valid choice in %j'
,
value
,
this
.
values
));
throw
new
sequelizeErrors
.
ValidationError
(
util
.
format
(
'%j is not a valid choice in %j'
,
value
,
this
.
values
));
}
}
...
...
lib/dialects/abstract/connection-manager.js
View file @
e739d81
...
@@ -59,7 +59,7 @@ ConnectionManager.prototype.refreshTypeParser = function(dataTypes) {
...
@@ -59,7 +59,7 @@ ConnectionManager.prototype.refreshTypeParser = function(dataTypes) {
throw
new
Error
(
'Parse function not supported for type '
+
dataType
.
key
+
' in dialect '
+
this
.
dialectName
);
throw
new
Error
(
'Parse function not supported for type '
+
dataType
.
key
+
' in dialect '
+
this
.
dialectName
);
}
}
}
}
}
,
this
);
}
.
bind
(
this
)
);
};
};
ConnectionManager
.
prototype
.
onProcessExit
=
function
()
{
ConnectionManager
.
prototype
.
onProcessExit
=
function
()
{
...
...
lib/dialects/abstract/query-generator.js
View file @
e739d81
...
@@ -1498,7 +1498,7 @@ var QueryGenerator = {
...
@@ -1498,7 +1498,7 @@ var QueryGenerator = {
var
validateOrder
=
function
(
order
)
{
var
validateOrder
=
function
(
order
)
{
if
(
order
instanceof
Utils
.
literal
)
return
;
if
(
order
instanceof
Utils
.
literal
)
return
;
if
(
!
_
.
contain
s
([
if
(
!
_
.
include
s
([
'ASC'
,
'ASC'
,
'DESC'
,
'DESC'
,
'ASC NULLS LAST'
,
'ASC NULLS LAST'
,
...
@@ -2215,7 +2215,7 @@ var QueryGenerator = {
...
@@ -2215,7 +2215,7 @@ var QueryGenerator = {
value
=
this
.
whereItemQuery
(
null
,
value
);
value
=
this
.
whereItemQuery
(
null
,
value
);
}
}
}
}
}
,
this
);
}
.
bind
(
this
)
);
}
}
if
(
comparator
===
'='
&&
value
===
null
)
{
if
(
comparator
===
'='
&&
value
===
null
)
{
...
...
lib/dialects/mssql/connection-manager.js
View file @
e739d81
...
@@ -5,7 +5,8 @@ var AbstractConnectionManager = require('../abstract/connection-manager')
...
@@ -5,7 +5,8 @@ var AbstractConnectionManager = require('../abstract/connection-manager')
,
Utils
=
require
(
'../../utils'
)
,
Utils
=
require
(
'../../utils'
)
,
Promise
=
require
(
'../../promise'
)
,
Promise
=
require
(
'../../promise'
)
,
sequelizeErrors
=
require
(
'../../errors'
)
,
sequelizeErrors
=
require
(
'../../errors'
)
,
parserStore
=
require
(
'../parserStore'
)(
'mssql'
);
,
parserStore
=
require
(
'../parserStore'
)(
'mssql'
)
,
_
=
require
(
'lodash'
);
ConnectionManager
=
function
(
dialect
,
sequelize
)
{
ConnectionManager
=
function
(
dialect
,
sequelize
)
{
AbstractConnectionManager
.
call
(
this
,
dialect
,
sequelize
);
AbstractConnectionManager
.
call
(
this
,
dialect
,
sequelize
);
...
@@ -76,9 +77,9 @@ ConnectionManager.prototype.connect = function(config) {
...
@@ -76,9 +77,9 @@ ConnectionManager.prototype.connect = function(config) {
switch
(
err
.
code
)
{
switch
(
err
.
code
)
{
case
'ESOCKET'
:
case
'ESOCKET'
:
if
(
Utils
.
_
.
contain
s
(
err
.
message
,
'connect EHOSTUNREACH'
))
{
if
(
_
.
include
s
(
err
.
message
,
'connect EHOSTUNREACH'
))
{
reject
(
new
sequelizeErrors
.
HostNotReachableError
(
err
));
reject
(
new
sequelizeErrors
.
HostNotReachableError
(
err
));
}
else
if
(
Utils
.
_
.
contain
s
(
err
.
message
,
'connect ECONNREFUSED'
))
{
}
else
if
(
_
.
include
s
(
err
.
message
,
'connect ECONNREFUSED'
))
{
reject
(
new
sequelizeErrors
.
ConnectionRefusedError
(
err
));
reject
(
new
sequelizeErrors
.
ConnectionRefusedError
(
err
));
}
else
{
}
else
{
reject
(
new
sequelizeErrors
.
ConnectionError
(
err
));
reject
(
new
sequelizeErrors
.
ConnectionError
(
err
));
...
...
lib/dialects/mssql/query.js
View file @
e739d81
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
var
Utils
=
require
(
'../../utils'
)
var
Utils
=
require
(
'../../utils'
)
,
AbstractQuery
=
require
(
'../abstract/query'
)
,
AbstractQuery
=
require
(
'../abstract/query'
)
,
sequelizeErrors
=
require
(
'../../errors.js'
)
,
sequelizeErrors
=
require
(
'../../errors.js'
)
,
parserStore
=
require
(
'../parserStore'
)(
'mssql'
);
,
parserStore
=
require
(
'../parserStore'
)(
'mssql'
),
_
=
require
(
'lodash'
);
var
Query
=
function
(
connection
,
sequelize
,
options
)
{
var
Query
=
function
(
connection
,
sequelize
,
options
)
{
this
.
connection
=
connection
;
this
.
connection
=
connection
;
...
@@ -41,7 +42,7 @@ Query.prototype.run = function(sql, parameters) {
...
@@ -41,7 +42,7 @@ Query.prototype.run = function(sql, parameters) {
var
promise
=
new
Utils
.
Promise
(
function
(
resolve
,
reject
)
{
var
promise
=
new
Utils
.
Promise
(
function
(
resolve
,
reject
)
{
// TRANSACTION SUPPORT
// TRANSACTION SUPPORT
if
(
Utils
.
_
.
contain
s
(
self
.
sql
,
'BEGIN TRANSACTION'
))
{
if
(
_
.
include
s
(
self
.
sql
,
'BEGIN TRANSACTION'
))
{
self
.
connection
.
beginTransaction
(
function
(
err
)
{
self
.
connection
.
beginTransaction
(
function
(
err
)
{
if
(
!!
err
)
{
if
(
!!
err
)
{
reject
(
self
.
formatError
(
err
));
reject
(
self
.
formatError
(
err
));
...
@@ -49,7 +50,7 @@ Query.prototype.run = function(sql, parameters) {
...
@@ -49,7 +50,7 @@ Query.prototype.run = function(sql, parameters) {
resolve
(
self
.
formatResults
());
resolve
(
self
.
formatResults
());
}
}
}
/* name, isolation_level */
);
}
/* name, isolation_level */
);
}
else
if
(
Utils
.
_
.
contain
s
(
self
.
sql
,
'COMMIT TRANSACTION'
))
{
}
else
if
(
_
.
include
s
(
self
.
sql
,
'COMMIT TRANSACTION'
))
{
self
.
connection
.
commitTransaction
(
function
(
err
)
{
self
.
connection
.
commitTransaction
(
function
(
err
)
{
if
(
!!
err
)
{
if
(
!!
err
)
{
reject
(
self
.
formatError
(
err
));
reject
(
self
.
formatError
(
err
));
...
@@ -57,7 +58,7 @@ Query.prototype.run = function(sql, parameters) {
...
@@ -57,7 +58,7 @@ Query.prototype.run = function(sql, parameters) {
resolve
(
self
.
formatResults
());
resolve
(
self
.
formatResults
());
}
}
});
});
}
else
if
(
Utils
.
_
.
contain
s
(
self
.
sql
,
'ROLLBACK TRANSACTION'
))
{
}
else
if
(
_
.
include
s
(
self
.
sql
,
'ROLLBACK TRANSACTION'
))
{
self
.
connection
.
rollbackTransaction
(
function
(
err
)
{
self
.
connection
.
rollbackTransaction
(
function
(
err
)
{
if
(
!!
err
)
{
if
(
!!
err
)
{
reject
(
self
.
formatError
(
err
));
reject
(
self
.
formatError
(
err
));
...
@@ -256,7 +257,7 @@ Query.prototype.isShowIndexesQuery = function () {
...
@@ -256,7 +257,7 @@ Query.prototype.isShowIndexesQuery = function () {
Query
.
prototype
.
handleShowIndexesQuery
=
function
(
data
)
{
Query
.
prototype
.
handleShowIndexesQuery
=
function
(
data
)
{
// Group by index name, and collect all fields
// Group by index name, and collect all fields
data
=
Utils
.
_
.
foldl
(
data
,
function
(
acc
,
item
)
{
data
=
_
.
reduce
(
data
,
function
(
acc
,
item
)
{
if
(
!
(
item
.
index_name
in
acc
))
{
if
(
!
(
item
.
index_name
in
acc
))
{
acc
[
item
.
index_name
]
=
item
;
acc
[
item
.
index_name
]
=
item
;
item
.
fields
=
[];
item
.
fields
=
[];
...
...
lib/dialects/mysql/query.js
View file @
e739d81
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
var
Utils
=
require
(
'../../utils'
)
var
Utils
=
require
(
'../../utils'
)
,
AbstractQuery
=
require
(
'../abstract/query'
)
,
AbstractQuery
=
require
(
'../abstract/query'
)
,
uuid
=
require
(
'node-uuid'
)
,
uuid
=
require
(
'node-uuid'
)
,
sequelizeErrors
=
require
(
'../../errors.js'
);
,
sequelizeErrors
=
require
(
'../../errors.js'
)
,
_
=
require
(
'lodash'
);
var
Query
=
function
(
connection
,
sequelize
,
options
)
{
var
Query
=
function
(
connection
,
sequelize
,
options
)
{
this
.
connection
=
connection
;
this
.
connection
=
connection
;
...
@@ -176,7 +177,7 @@ Query.prototype.formatError = function (err) {
...
@@ -176,7 +177,7 @@ Query.prototype.formatError = function (err) {
Query
.
prototype
.
handleShowIndexesQuery
=
function
(
data
)
{
Query
.
prototype
.
handleShowIndexesQuery
=
function
(
data
)
{
// Group by index name, and collect all fields
// Group by index name, and collect all fields
data
=
Utils
.
_
.
foldl
(
data
,
function
(
acc
,
item
)
{
data
=
_
.
reduce
(
data
,
function
(
acc
,
item
)
{
if
(
!
(
item
.
Key_name
in
acc
))
{
if
(
!
(
item
.
Key_name
in
acc
))
{
acc
[
item
.
Key_name
]
=
item
;
acc
[
item
.
Key_name
]
=
item
;
item
.
fields
=
[];
item
.
fields
=
[];
...
...
lib/dialects/postgres/query-generator.js
View file @
e739d81
...
@@ -6,7 +6,8 @@ var Utils = require('../../utils')
...
@@ -6,7 +6,8 @@ var Utils = require('../../utils')
,
DataTypes
=
require
(
'../../data-types'
)
,
DataTypes
=
require
(
'../../data-types'
)
,
AbstractQueryGenerator
=
require
(
'../abstract/query-generator'
)
,
AbstractQueryGenerator
=
require
(
'../abstract/query-generator'
)
,
primaryKeys
=
{}
,
primaryKeys
=
{}
,
semver
=
require
(
'semver'
);
,
semver
=
require
(
'semver'
)
,
_
=
require
(
'lodash'
);
var
QueryGenerator
=
{
var
QueryGenerator
=
{
options
:
{},
options
:
{},
...
@@ -141,14 +142,13 @@ var QueryGenerator = {
...
@@ -141,14 +142,13 @@ var QueryGenerator = {
},
},
handleSequelizeMethod
:
function
(
smth
,
tableName
,
factory
,
options
,
prepend
)
{
handleSequelizeMethod
:
function
(
smth
,
tableName
,
factory
,
options
,
prepend
)
{
var
_
=
Utils
.
_
;
if
(
smth
instanceof
Utils
.
json
)
{
if
(
smth
instanceof
Utils
.
json
)
{
// Parse nested object
// Parse nested object
if
(
smth
.
conditions
)
{
if
(
smth
.
conditions
)
{
var
conditions
=
_
.
map
(
this
.
parseConditionObject
(
smth
.
conditions
),
function
generateSql
(
condition
)
{
var
conditions
=
_
.
map
(
this
.
parseConditionObject
(
smth
.
conditions
),
function
generateSql
(
condition
)
{
return
util
.
format
(
"%s#>>'{%s}' = '%s'"
,
return
util
.
format
(
"%s#>>'{%s}' = '%s'"
,
_
.
first
(
condition
.
path
),
_
.
first
(
condition
.
path
),
_
.
rest
(
condition
.
path
).
join
(
','
),
_
.
tail
(
condition
.
path
).
join
(
','
),
condition
.
value
);
condition
.
value
);
});
});
...
@@ -157,14 +157,14 @@ var QueryGenerator = {
...
@@ -157,14 +157,14 @@ var QueryGenerator = {
var
str
;
var
str
;
// Allow specifying conditions using the postgres json syntax
// Allow specifying conditions using the postgres json syntax
if
(
_
.
any
([
'->'
,
'->>'
,
'#>'
],
_
.
partial
(
_
.
contain
s
,
smth
.
path
)))
{
if
(
_
.
some
([
'->'
,
'->>'
,
'#>'
],
_
.
partial
(
_
.
include
s
,
smth
.
path
)))
{
str
=
smth
.
path
;
str
=
smth
.
path
;
}
else
{
}
else
{
// Also support json dot notation
// Also support json dot notation
var
path
=
smth
.
path
.
split
(
'.'
);
var
path
=
smth
.
path
.
split
(
'.'
);
str
=
util
.
format
(
"%s#>>'{%s}'"
,
str
=
util
.
format
(
"%s#>>'{%s}'"
,
_
.
first
(
path
),
_
.
first
(
path
),
_
.
rest
(
path
).
join
(
','
));
_
.
tail
(
path
).
join
(
','
));
}
}
if
(
smth
.
value
)
{
if
(
smth
.
value
)
{
...
...
lib/instance.js
View file @
e739d81
...
@@ -427,9 +427,9 @@ Instance.prototype.previous = function(key) {
...
@@ -427,9 +427,9 @@ Instance.prototype.previous = function(key) {
return
this
.
_previousDataValues
[
key
];
return
this
.
_previousDataValues
[
key
];
}
}
return
_
.
pick
(
this
.
_previousDataValues
,
function
(
value
,
key
)
{
return
_
.
pick
By
(
this
.
_previousDataValues
,
function
(
value
,
key
)
{
return
this
.
changed
(
key
);
return
this
.
changed
(
key
);
}
,
this
);
}
.
bind
(
this
)
);
};
};
Instance
.
prototype
.
_setInclude
=
function
(
key
,
value
,
options
)
{
Instance
.
prototype
.
_setInclude
=
function
(
key
,
value
,
options
)
{
...
@@ -591,7 +591,7 @@ Instance.prototype.save = function(options) {
...
@@ -591,7 +591,7 @@ Instance.prototype.save = function(options) {
}
}
});
});
options
.
fields
=
_
.
uniq
ue
(
options
.
fields
.
concat
(
hookChanged
));
options
.
fields
=
_
.
uniq
(
options
.
fields
.
concat
(
hookChanged
));
}
}
if
(
hookChanged
)
{
if
(
hookChanged
)
{
...
@@ -1043,7 +1043,7 @@ Instance.prototype.equals = function(other) {
...
@@ -1043,7 +1043,7 @@ Instance.prototype.equals = function(other) {
Instance
.
prototype
.
equalsOneOf
=
function
(
others
)
{
Instance
.
prototype
.
equalsOneOf
=
function
(
others
)
{
var
self
=
this
;
var
self
=
this
;
return
_
.
any
(
others
,
function
(
other
)
{
return
_
.
some
(
others
,
function
(
other
)
{
return
self
.
equals
(
other
);
return
self
.
equals
(
other
);
});
});
};
};
...
...
lib/model.js
View file @
e739d81
...
@@ -64,17 +64,17 @@ var Model = function(name, attributes, options) {
...
@@ -64,17 +64,17 @@ var Model = function(name, attributes, options) {
this
.
$schemaDelimiter
=
this
.
options
.
schemaDelimiter
;
this
.
$schemaDelimiter
=
this
.
options
.
schemaDelimiter
;
// error check options
// error check options
Utils
.
_
.
each
(
options
.
validate
,
function
(
validator
,
validatorType
)
{
_
.
each
(
options
.
validate
,
function
(
validator
,
validatorType
)
{
if
(
Utils
.
_
.
contain
s
(
Utils
.
_
.
keys
(
attributes
),
validatorType
))
{
if
(
_
.
include
s
(
Utils
.
_
.
keys
(
attributes
),
validatorType
))
{
throw
new
Error
(
'A model validator function must not have the same name as a field. Model: '
+
name
+
', field/validation name: '
+
validatorType
);
throw
new
Error
(
'A model validator function must not have the same name as a field. Model: '
+
name
+
', field/validation name: '
+
validatorType
);
}
}
if
(
!
Utils
.
_
.
isFunction
(
validator
))
{
if
(
!
_
.
isFunction
(
validator
))
{
throw
new
Error
(
'Members of the validate option must be functions. Model: '
+
name
+
', error with validate member '
+
validatorType
);
throw
new
Error
(
'Members of the validate option must be functions. Model: '
+
name
+
', error with validate member '
+
validatorType
);
}
}
});
});
this
.
attributes
=
this
.
rawAttributes
=
Utils
.
_
.
mapValues
(
attributes
,
function
(
attribute
,
name
)
{
this
.
attributes
=
this
.
rawAttributes
=
_
.
mapValues
(
attributes
,
function
(
attribute
,
name
)
{
if
(
!
Utils
.
_
.
isPlainObject
(
attribute
))
{
if
(
!
Utils
.
_
.
isPlainObject
(
attribute
))
{
attribute
=
{
type
:
attribute
};
attribute
=
{
type
:
attribute
};
}
}
...
@@ -95,15 +95,19 @@ var Model = function(name, attributes, options) {
...
@@ -95,15 +95,19 @@ var Model = function(name, attributes, options) {
}
}
return
attribute
;
return
attribute
;
}
,
this
);
}
.
bind
(
this
)
);
};
};
Object
.
defineProperty
(
Model
.
prototype
,
'QueryInterface'
,
{
Object
.
defineProperty
(
Model
.
prototype
,
'QueryInterface'
,
{
get
:
function
()
{
return
this
.
modelManager
.
sequelize
.
getQueryInterface
();
}
get
:
function
()
{
return
this
.
modelManager
.
sequelize
.
getQueryInterface
();
}
});
});
Object
.
defineProperty
(
Model
.
prototype
,
'QueryGenerator'
,
{
Object
.
defineProperty
(
Model
.
prototype
,
'QueryGenerator'
,
{
get
:
function
()
{
return
this
.
QueryInterface
.
QueryGenerator
;
}
get
:
function
()
{
return
this
.
QueryInterface
.
QueryGenerator
;
}
});
});
Model
.
prototype
.
toString
=
function
()
{
Model
.
prototype
.
toString
=
function
()
{
...
@@ -158,7 +162,7 @@ var addDefaultAttributes = function() {
...
@@ -158,7 +162,7 @@ var addDefaultAttributes = function() {
// Add id if no primary key was manually added to definition
// Add id if no primary key was manually added to definition
// Can't use this.primaryKeys here, since this function is called before PKs are identified
// Can't use this.primaryKeys here, since this function is called before PKs are identified
if
(
!
_
.
any
(
this
.
rawAttributes
,
'primaryKey'
))
{
if
(
!
_
.
some
(
this
.
rawAttributes
,
'primaryKey'
))
{
if
(
'id'
in
this
.
rawAttributes
)
{
if
(
'id'
in
this
.
rawAttributes
)
{
// Something is fishy here!
// Something is fishy here!
throw
new
Error
(
"A column called 'id' was added to the attributes of '"
+
this
.
tableName
+
"' but not marked with 'primaryKey: true'"
);
throw
new
Error
(
"A column called 'id' was added to the attributes of '"
+
this
.
tableName
+
"' but not marked with 'primaryKey: true'"
);
...
@@ -530,7 +534,7 @@ validateIncludedElement = function(include, tableNames, options) {
...
@@ -530,7 +534,7 @@ validateIncludedElement = function(include, tableNames, options) {
if
(
include
.
attributes
.
length
)
{
if
(
include
.
attributes
.
length
)
{
_
.
each
(
include
.
model
.
primaryKeys
,
function
(
attr
,
key
)
{
_
.
each
(
include
.
model
.
primaryKeys
,
function
(
attr
,
key
)
{
// Include the primary key if its not already take - take into account that the pk might be aliassed (due to a .field prop)
// Include the primary key if its not already take - take into account that the pk might be aliassed (due to a .field prop)
if
(
!
_
.
any
(
include
.
attributes
,
function
(
includeAttr
)
{
if
(
!
_
.
some
(
include
.
attributes
,
function
(
includeAttr
)
{
if
(
attr
.
field
!==
key
)
{
if
(
attr
.
field
!==
key
)
{
return
Array
.
isArray
(
includeAttr
)
&&
includeAttr
[
0
]
===
attr
.
field
&&
includeAttr
[
1
]
===
key
;
return
Array
.
isArray
(
includeAttr
)
&&
includeAttr
[
0
]
===
attr
.
field
&&
includeAttr
[
1
]
===
key
;
}
}
...
@@ -698,7 +702,7 @@ Model.prototype.init = function(modelManager) {
...
@@ -698,7 +702,7 @@ Model.prototype.init = function(modelManager) {
if
(
_
.
isPlainObject
(
scope
))
{
if
(
_
.
isPlainObject
(
scope
))
{
conformOptions
(
scope
,
this
);
conformOptions
(
scope
,
this
);
}
}
}
,
this
);
}
.
bind
(
this
)
);
// Instance prototype
// Instance prototype
this
.
Instance
=
function
()
{
this
.
Instance
=
function
()
{
...
@@ -799,7 +803,7 @@ Model.prototype.refreshAttributes = function() {
...
@@ -799,7 +803,7 @@ Model.prototype.refreshAttributes = function() {
this
.
primaryKeys
=
{};
this
.
primaryKeys
=
{};
self
.
options
.
uniqueKeys
=
{};
self
.
options
.
uniqueKeys
=
{};
Utils
.
_
.
each
(
this
.
rawAttributes
,
function
(
definition
,
name
)
{
_
.
each
(
this
.
rawAttributes
,
function
(
definition
,
name
)
{
definition
.
type
=
self
.
sequelize
.
normalizeDataType
(
definition
.
type
);
definition
.
type
=
self
.
sequelize
.
normalizeDataType
(
definition
.
type
);
definition
.
Model
=
self
;
definition
.
Model
=
self
;
...
@@ -993,8 +997,8 @@ Model.prototype.sync = function(options) {
...
@@ -993,8 +997,8 @@ Model.prototype.sync = function(options) {
// Assign an auto-generated name to indexes which are not named by the user
// Assign an auto-generated name to indexes which are not named by the user
self
.
options
.
indexes
=
self
.
QueryInterface
.
nameIndexes
(
self
.
options
.
indexes
,
self
.
tableName
);
self
.
options
.
indexes
=
self
.
QueryInterface
.
nameIndexes
(
self
.
options
.
indexes
,
self
.
tableName
);
indexes
=
Utils
.
_
.
filter
(
self
.
options
.
indexes
,
function
(
item1
)
{
indexes
=
_
.
filter
(
self
.
options
.
indexes
,
function
(
item1
)
{
return
!
Utils
.
_
.
any
(
indexes
,
function
(
item2
)
{
return
!
_
.
some
(
indexes
,
function
(
item2
)
{
return
item1
.
name
===
item2
.
name
;
return
item1
.
name
===
item2
.
name
;
});
});
});
});
...
@@ -1201,7 +1205,7 @@ Model.prototype.scope = function(option) {
...
@@ -1201,7 +1205,7 @@ Model.prototype.scope = function(option) {
}
}
if
(
!!
scope
)
{
if
(
!!
scope
)
{
_
.
assign
(
self
.
$scope
,
scope
,
function
scopeCustomizer
(
objectValue
,
sourceValue
,
key
)
{
_
.
assign
With
(
self
.
$scope
,
scope
,
function
scopeCustomizer
(
objectValue
,
sourceValue
,
key
)
{
if
(
key
===
'where'
)
{
if
(
key
===
'where'
)
{
return
Array
.
isArray
(
sourceValue
)
?
sourceValue
:
_
.
assign
(
objectValue
||
{},
sourceValue
);
return
Array
.
isArray
(
sourceValue
)
?
sourceValue
:
_
.
assign
(
objectValue
||
{},
sourceValue
);
}
else
if
(
([
'attributes'
,
'include'
].
indexOf
(
key
)
>=
0
)
&&
Array
.
isArray
(
objectValue
)
&&
Array
.
isArray
(
sourceValue
))
{
}
else
if
(
([
'attributes'
,
'include'
].
indexOf
(
key
)
>=
0
)
&&
Array
.
isArray
(
objectValue
)
&&
Array
.
isArray
(
sourceValue
))
{
...
@@ -1381,7 +1385,6 @@ Model.prototype.findAll = function(options) {
...
@@ -1381,7 +1385,6 @@ Model.prototype.findAll = function(options) {
}).
then
(
function
()
{
}).
then
(
function
()
{
originalOptions
=
optClone
(
options
);
originalOptions
=
optClone
(
options
);
options
.
tableNames
=
Object
.
keys
(
tableNames
);
options
.
tableNames
=
Object
.
keys
(
tableNames
);
return
this
.
QueryInterface
.
select
(
this
,
this
.
getTableName
(
options
),
options
);
return
this
.
QueryInterface
.
select
(
this
,
this
.
getTableName
(
options
),
options
);
}).
tap
(
function
(
results
)
{
}).
tap
(
function
(
results
)
{
if
(
options
.
hooks
)
{
if
(
options
.
hooks
)
{
...
...
lib/utils.js
View file @
e739d81
...
@@ -35,12 +35,12 @@ var Utils = module.exports = {
...
@@ -35,12 +35,12 @@ var Utils = module.exports = {
},
},
// Same concept as _.merge, but don't overwrite properties that have already been assigned
// Same concept as _.merge, but don't overwrite properties that have already been assigned
mergeDefaults
:
function
(
a
,
b
)
{
mergeDefaults
:
function
(
a
,
b
)
{
return
this
.
_
.
merge
(
a
,
b
,
function
(
objectValue
,
sourceValue
)
{
return
_
.
mergeWith
(
a
,
b
,
function
(
objectValue
,
sourceValue
)
{
// If it's an object, let _ handle it this time, we will be called again for each property
// If it's an object, let _ handle it this time, we will be called again for each property
if
(
!
this
.
_
.
isPlainObject
(
objectValue
)
&&
objectValue
!==
undefined
)
{
if
(
!
this
.
_
.
isPlainObject
(
objectValue
)
&&
objectValue
!==
undefined
)
{
return
objectValue
;
return
objectValue
;
}
}
}
,
this
);
}
.
bind
(
this
)
);
},
},
lowercaseFirst
:
function
(
s
)
{
lowercaseFirst
:
function
(
s
)
{
return
s
[
0
].
toLowerCase
()
+
s
.
slice
(
1
);
return
s
[
0
].
toLowerCase
()
+
s
.
slice
(
1
);
...
@@ -64,7 +64,7 @@ var Utils = module.exports = {
...
@@ -64,7 +64,7 @@ var Utils = module.exports = {
return
SqlString
.
formatNamedParameters
(
sql
,
parameters
,
timeZone
,
dialect
);
return
SqlString
.
formatNamedParameters
(
sql
,
parameters
,
timeZone
,
dialect
);
},
},
cloneDeep
:
function
(
obj
,
fn
)
{
cloneDeep
:
function
(
obj
,
fn
)
{
return
_
.
cloneDeep
(
obj
,
function
(
elem
)
{
return
_
.
cloneDeep
With
(
obj
,
function
(
elem
)
{
// Do not try to customize cloning of plain objects and strings
// Do not try to customize cloning of plain objects and strings
if
(
Array
.
isArray
(
elem
)
||
_
.
isPlainObject
(
elem
))
{
if
(
Array
.
isArray
(
elem
)
||
_
.
isPlainObject
(
elem
))
{
return
undefined
;
return
undefined
;
...
@@ -89,7 +89,7 @@ var Utils = module.exports = {
...
@@ -89,7 +89,7 @@ var Utils = module.exports = {
}
}
}.
bind
(
Model
));
}.
bind
(
Model
));
options
.
attributes
=
_
.
without
.
apply
(
_
,
[
options
.
attributes
].
concat
(
Model
.
_virtualAttributes
));
options
.
attributes
=
_
.
without
.
apply
(
_
,
[
options
.
attributes
].
concat
(
Model
.
_virtualAttributes
));
options
.
attributes
=
_
.
uniq
ue
(
options
.
attributes
);
options
.
attributes
=
_
.
uniq
(
options
.
attributes
);
}
}
Utils
.
mapOptionFieldNames
(
options
,
Model
);
Utils
.
mapOptionFieldNames
(
options
,
Model
);
...
...
test/integration/associations/belongs-to-many.test.js
View file @
e739d81
...
@@ -1780,7 +1780,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
...
@@ -1780,7 +1780,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
return
self
.
sequelize
.
getQueryInterface
().
showAllTables
();
return
self
.
sequelize
.
getQueryInterface
().
showAllTables
();
}).
then
(
function
(
result
)
{
}).
then
(
function
(
result
)
{
if
(
dialect
===
'mssql'
/* current.dialect.supports.schemas */
)
{
if
(
dialect
===
'mssql'
/* current.dialect.supports.schemas */
)
{
result
=
_
.
pluck
(
result
,
'tableName'
);
result
=
_
.
map
(
result
,
'tableName'
);
}
}
expect
(
result
.
indexOf
(
'group_user'
)).
not
.
to
.
equal
(
-
1
);
expect
(
result
.
indexOf
(
'group_user'
)).
not
.
to
.
equal
(
-
1
);
...
@@ -1800,7 +1800,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
...
@@ -1800,7 +1800,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
return
self
.
sequelize
.
getQueryInterface
().
showAllTables
();
return
self
.
sequelize
.
getQueryInterface
().
showAllTables
();
}).
then
(
function
(
result
)
{
}).
then
(
function
(
result
)
{
if
(
dialect
===
'mssql'
/* current.dialect.supports.schemas */
)
{
if
(
dialect
===
'mssql'
/* current.dialect.supports.schemas */
)
{
result
=
_
.
pluck
(
result
,
'tableName'
);
result
=
_
.
map
(
result
,
'tableName'
);
}
}
expect
(
result
.
indexOf
(
'user_groups'
)).
not
.
to
.
equal
(
-
1
);
expect
(
result
.
indexOf
(
'user_groups'
)).
not
.
to
.
equal
(
-
1
);
...
...
test/integration/associations/scope.test.js
View file @
e739d81
...
@@ -43,7 +43,8 @@ describe(Support.getTestDialectTeaser('associations'), function() {
...
@@ -43,7 +43,8 @@ describe(Support.getTestDialectTeaser('associations'), function() {
foreignKey
:
'commentable_id'
,
foreignKey
:
'commentable_id'
,
scope
:
{
scope
:
{
commentable
:
'post'
commentable
:
'post'
}
},
constraints
:
false
});
});
this
.
Post
.
hasOne
(
this
.
Comment
,
{
this
.
Post
.
hasOne
(
this
.
Comment
,
{
foreignKey
:
'commentable_id'
,
foreignKey
:
'commentable_id'
,
...
@@ -51,33 +52,39 @@ describe(Support.getTestDialectTeaser('associations'), function() {
...
@@ -51,33 +52,39 @@ describe(Support.getTestDialectTeaser('associations'), function() {
scope
:
{
scope
:
{
commentable
:
'post'
,
commentable
:
'post'
,
isMain
:
true
isMain
:
true
}
},
constraints
:
false
});
});
this
.
Comment
.
belongsTo
(
this
.
Post
,
{
this
.
Comment
.
belongsTo
(
this
.
Post
,
{
foreignKey
:
'commentable_id'
,
foreignKey
:
'commentable_id'
,
as
:
'post'
as
:
'post'
,
constraints
:
false
});
});
this
.
Image
.
hasMany
(
this
.
Comment
,
{
this
.
Image
.
hasMany
(
this
.
Comment
,
{
foreignKey
:
'commentable_id'
,
foreignKey
:
'commentable_id'
,
scope
:
{
scope
:
{
commentable
:
'image'
commentable
:
'image'
}
},
constraints
:
false
});
});
this
.
Comment
.
belongsTo
(
this
.
Image
,
{
this
.
Comment
.
belongsTo
(
this
.
Image
,
{
foreignKey
:
'commentable_id'
,
foreignKey
:
'commentable_id'
,
as
:
'image'
as
:
'image'
,
constraints
:
false
});
});
this
.
Question
.
hasMany
(
this
.
Comment
,
{
this
.
Question
.
hasMany
(
this
.
Comment
,
{
foreignKey
:
'commentable_id'
,
foreignKey
:
'commentable_id'
,
scope
:
{
scope
:
{
commentable
:
'question'
commentable
:
'question'
}
},
constraints
:
false
});
});
this
.
Comment
.
belongsTo
(
this
.
Question
,
{
this
.
Comment
.
belongsTo
(
this
.
Question
,
{
foreignKey
:
'commentable_id'
,
foreignKey
:
'commentable_id'
,
as
:
'question'
as
:
'question'
,
constraints
:
false
});
});
});
});
...
...
test/integration/query-interface.test.js
View file @
e739d81
...
@@ -59,7 +59,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
...
@@ -59,7 +59,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
return
self
.
queryInterface
.
dropAllTables
({
skip
:
[
'skipme'
]}).
then
(
function
()
{
return
self
.
queryInterface
.
dropAllTables
({
skip
:
[
'skipme'
]}).
then
(
function
()
{
return
self
.
queryInterface
.
showAllTables
().
then
(
function
(
tableNames
)
{
return
self
.
queryInterface
.
showAllTables
().
then
(
function
(
tableNames
)
{
if
(
dialect
===
'mssql'
/* current.dialect.supports.schemas */
)
{
if
(
dialect
===
'mssql'
/* current.dialect.supports.schemas */
)
{
tableNames
=
_
.
pluck
(
tableNames
,
'tableName'
);
tableNames
=
_
.
map
(
tableNames
,
'tableName'
);
}
}
expect
(
tableNames
).
to
.
contain
(
'skipme'
);
expect
(
tableNames
).
to
.
contain
(
'skipme'
);
});
});
...
...
test/integration/sequelize.test.js
View file @
e739d81
...
@@ -899,7 +899,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
...
@@ -899,7 +899,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
return
Photo
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Photo
.
sync
({
force
:
true
}).
then
(
function
()
{
return
self
.
sequelize
.
getQueryInterface
().
showAllTables
().
then
(
function
(
tableNames
)
{
return
self
.
sequelize
.
getQueryInterface
().
showAllTables
().
then
(
function
(
tableNames
)
{
if
(
dialect
===
'mssql'
/* current.dialect.supports.schemas */
)
{
if
(
dialect
===
'mssql'
/* current.dialect.supports.schemas */
)
{
tableNames
=
_
.
pluck
(
tableNames
,
'tableName'
);
tableNames
=
_
.
map
(
tableNames
,
'tableName'
);
}
}
expect
(
tableNames
).
to
.
include
(
'photos'
);
expect
(
tableNames
).
to
.
include
(
'photos'
);
});
});
...
...
test/integration/transaction.test.js
View file @
e739d81
...
@@ -21,7 +21,6 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
...
@@ -21,7 +21,6 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
this
.
sinon
.
restore
();
this
.
sinon
.
restore
();
});
});
this
.
timeout
(
5000
);
describe
(
'constructor'
,
function
()
{
describe
(
'constructor'
,
function
()
{
it
(
'stores options'
,
function
()
{
it
(
'stores options'
,
function
()
{
var
transaction
=
new
Transaction
(
this
.
sequelize
);
var
transaction
=
new
Transaction
(
this
.
sequelize
);
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment