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 b11f57f3
authored
May 26, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:sequelize/sequelize
2 parents
bb37cd30
d3dc86ee
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
75 additions
and
61 deletions
.jshintrc
.travis.yml
Makefile
lib/dialects/abstract/query-generator.js
lib/dialects/abstract/query.js
lib/instance.js
lib/model.js
lib/query-interface.js
package.json
test/model/attributes.test.js
.jshintrc
View file @
b11f57f
/*
{
"globals": {
"spyOn": false,
"it": false,
"console": false,
"describe": false,
"expect": false,
"beforeEach": false,
"afterEach": false,
"waits": false,
"waitsFor": false,
"runs": false
},
"node": true,
"camelcase": true,
"curly": true,
"forin": true,
"indent": 2,
"unused": true,
"asi": true,
"evil": false,
"laxcomma": true,
"es5": true,
"quotmark": false,
"undef": true,
"strict": false
}
*/
{
"bitwise":false,
"boss":true,
...
...
.travis.yml
View file @
b11f57f
...
...
@@ -21,7 +21,6 @@ env:
language
:
node_js
node_js
:
-
"
0.8"
-
"
0.10"
branches
:
...
...
@@ -42,4 +41,4 @@ matrix:
allow_failures
:
-
node_js
:
"
0.10"
env
:
COVERAGE=true
\ No newline at end of file
env
:
COVERAGE=true
Makefile
View file @
b11f57f
...
...
@@ -16,12 +16,15 @@ test: codeclimate
else
test
:
@
if
[
"
$$
GREP"
]
;
then
\
make teaser
&&
./node_modules/mocha/bin/mocha --globals setImmediate,clearImmediate --check-leaks --colors -t 10000 --reporter
$(REPORTER)
-g
"
$$
GREP"
$(TESTS)
;
\
make
jshint
&&
make
teaser
&&
./node_modules/mocha/bin/mocha --globals setImmediate,clearImmediate --check-leaks --colors -t 10000 --reporter
$(REPORTER)
-g
"
$$
GREP"
$(TESTS)
;
\
else
\
make teaser
&&
./node_modules/mocha/bin/mocha --globals setImmediate,clearImmediate --check-leaks --colors -t 10000 --reporter
$(REPORTER)
$(TESTS)
;
\
make
jshint
&&
make
teaser
&&
./node_modules/mocha/bin/mocha --globals setImmediate,clearImmediate --check-leaks --colors -t 10000 --reporter
$(REPORTER)
$(TESTS)
;
\
fi
endif
jshint
:
./node_modules/.bin/jshint lib
cover
:
rm -rf coverage
\
make teaser
&&
./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -t 10000
$(TESTS)
;
\
...
...
lib/dialects/abstract/query-generator.js
View file @
b11f57f
...
...
@@ -785,13 +785,18 @@ module.exports = (function() {
}
}
}
else
{
var
primaryKeysLeft
=
association
.
associationType
===
'BelongsTo'
?
association
.
target
.
primaryKeyAttributes
:
include
.
association
.
source
.
primaryKeyAttributes
var
left
=
association
.
associationType
===
'BelongsTo'
?
association
.
target
:
include
.
association
.
source
,
primaryKeysLeft
=
association
.
associationType
===
'BelongsTo'
?
left
.
primaryKeyAttributes
:
left
.
primaryKeyAttributes
,
tableLeft
=
association
.
associationType
===
'BelongsTo'
?
as
:
parentTable
,
attrLeft
=
primaryKeysLeft
[
0
]
,
tableRight
=
association
.
associationType
===
'BelongsTo'
?
parentTable
:
as
,
attrRight
=
association
.
identifier
,
joinOn
;
if
(
left
.
rawAttributes
[
attrLeft
].
field
)
{
attrLeft
=
left
.
rawAttributes
[
attrLeft
].
field
;
}
// Filter statement
// Used by both join and subquery where
joinOn
=
...
...
lib/dialects/abstract/query.js
View file @
b11f57f
This diff is collapsed.
Click to expand it.
lib/instance.js
View file @
b11f57f
...
...
@@ -362,8 +362,8 @@ module.exports = (function() {
,
self
=
this
,
accessor
=
Utils
.
_
.
camelize
(
key
)
,
childOptions
,
primaryKeyAttribute
=
include
.
model
.
primaryKeyAttribute
,
isEmpty
=
value
[
0
]
&&
value
[
0
][
primaryKeyAttribute
]
===
null
;
,
primaryKeyAttribute
=
include
.
model
.
primaryKeyAttribute
,
isEmpty
;
if
(
!
isEmpty
)
{
childOptions
=
{
...
...
@@ -382,9 +382,15 @@ module.exports = (function() {
accessor
=
accessor
.
slice
(
0
,
1
).
toLowerCase
()
+
accessor
.
slice
(
1
);
if
(
association
.
isSingleAssociation
)
{
if
(
Array
.
isArray
(
value
))
{
value
=
value
[
0
];
}
isEmpty
=
value
&&
value
[
primaryKeyAttribute
]
===
null
;
accessor
=
Utils
.
singularize
(
accessor
,
self
.
Model
.
options
.
language
);
self
[
accessor
]
=
self
.
dataValues
[
accessor
]
=
isEmpty
?
null
:
include
.
model
.
build
(
value
[
0
]
,
childOptions
);
self
[
accessor
]
=
self
.
dataValues
[
accessor
]
=
isEmpty
?
null
:
include
.
model
.
build
(
value
,
childOptions
);
}
else
{
isEmpty
=
value
[
0
]
&&
value
[
0
][
primaryKeyAttribute
]
===
null
;
self
[
accessor
]
=
self
.
dataValues
[
accessor
]
=
isEmpty
?
[]
:
include
.
model
.
bulkBuild
(
value
,
childOptions
);
}
}
...
...
@@ -506,6 +512,16 @@ module.exports = (function() {
}
else
{
var
identifier
=
self
.
primaryKeyValues
;
if
(
identifier
)
{
for
(
var
attrName
in
identifier
)
{
// Field name mapping
if
(
self
.
Model
.
rawAttributes
[
attrName
].
field
)
{
identifier
[
self
.
Model
.
rawAttributes
[
attrName
].
field
]
=
identifier
[
attrName
];
delete
identifier
[
attrName
];
}
}
}
if
(
identifier
===
null
&&
self
.
__options
.
whereCollection
!==
null
)
{
identifier
=
self
.
__options
.
whereCollection
;
}
...
...
lib/model.js
View file @
b11f57f
...
...
@@ -1230,8 +1230,17 @@ module.exports = (function() {
}
});
// Map attributes for serial identification
var
attributes
=
{};
for
(
var
attr
in
self
.
rawAttributes
)
{
attributes
[
attr
]
=
self
.
rawAttributes
[
attr
];
if
(
self
.
rawAttributes
[
attr
].
field
)
{
attributes
[
self
.
rawAttributes
[
attr
].
field
]
=
self
.
rawAttributes
[
attr
];
}
}
// Insert all records at once
return
self
.
QueryInterface
.
bulkInsert
(
self
.
getTableName
(),
records
,
options
,
self
).
then
(
runAfterCreate
);
return
self
.
QueryInterface
.
bulkInsert
(
self
.
getTableName
(),
records
,
options
,
attributes
).
then
(
runAfterCreate
);
}
else
{
// Records were already saved while running create / update hooks
return
runAfterCreate
();
...
...
@@ -1461,6 +1470,9 @@ module.exports = (function() {
var
mapFieldNames
=
function
(
options
,
Model
)
{
if
(
options
.
attributes
)
{
options
.
attributes
=
options
.
attributes
.
map
(
function
(
attr
)
{
// Object lookups will force any variable to strings, we don't want that for special objects etc
if
(
typeof
attr
!==
"string"
)
return
attr
;
// Map attributes to aliased syntax attributes
if
(
Model
.
rawAttributes
[
attr
]
&&
Model
.
rawAttributes
[
attr
].
field
)
{
return
[
Model
.
rawAttributes
[
attr
].
field
,
attr
];
}
...
...
@@ -1470,9 +1482,11 @@ module.exports = (function() {
if
(
options
.
where
)
{
for
(
var
attr
in
options
.
where
)
{
if
(
Model
.
rawAttributes
[
attr
]
&&
Model
.
rawAttributes
[
attr
].
field
)
{
options
.
where
[
Model
.
rawAttributes
[
attr
].
field
]
=
options
.
where
[
attr
];
delete
options
.
where
[
attr
];
if
(
typeof
attr
===
"string"
)
{
if
(
Model
.
rawAttributes
[
attr
]
&&
Model
.
rawAttributes
[
attr
].
field
)
{
options
.
where
[
Model
.
rawAttributes
[
attr
].
field
]
=
options
.
where
[
attr
];
delete
options
.
where
[
attr
];
}
}
}
}
...
...
lib/query-interface.js
View file @
b11f57f
...
...
@@ -423,8 +423,8 @@ module.exports = (function() {
});
};
QueryInterface
.
prototype
.
bulkInsert
=
function
(
tableName
,
records
,
options
,
Model
)
{
var
sql
=
this
.
QueryGenerator
.
bulkInsertQuery
(
tableName
,
records
,
options
,
Model
.
rawA
ttributes
);
QueryInterface
.
prototype
.
bulkInsert
=
function
(
tableName
,
records
,
options
,
attributes
)
{
var
sql
=
this
.
QueryGenerator
.
bulkInsertQuery
(
tableName
,
records
,
options
,
a
ttributes
);
return
this
.
sequelize
.
query
(
sql
,
null
,
options
);
};
...
...
package.json
View file @
b11f57f
...
...
@@ -71,7 +71,8 @@
"async"
:
"~0.2.10"
,
"coffee-script"
:
"~1.7.1"
,
"markdox"
:
"0.1.4"
,
"sinon-chai"
:
"~2.5.0"
"sinon-chai"
:
"~2.5.0"
,
"jshint"
:
">=2.4.2"
},
"keywords"
:
[
"mysql"
,
...
...
test/model/attributes.test.js
View file @
b11f57f
...
...
@@ -7,10 +7,10 @@ var chai = require('chai')
,
Support
=
require
(
__dirname
+
'/../support'
)
,
DataTypes
=
require
(
__dirname
+
"/../../lib/data-types"
)
,
dialect
=
Support
.
getTestDialect
()
,
datetime
=
require
(
'chai-datetime'
)
,
datetime
=
require
(
'chai-datetime'
)
;
chai
.
use
(
datetime
)
chai
.
config
.
includeStack
=
true
chai
.
use
(
datetime
)
;
chai
.
config
.
includeStack
=
true
;
describe
(
Support
.
getTestDialectTeaser
(
"Model"
),
function
()
{
describe
(
'attributes'
,
function
()
{
...
...
@@ -19,6 +19,13 @@ describe(Support.getTestDialectTeaser("Model"), function () {
var
queryInterface
=
this
.
sequelize
.
getQueryInterface
();
this
.
User
=
this
.
sequelize
.
define
(
'user'
,
{
id
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
,
primaryKey
:
true
,
autoIncrement
:
true
,
field
:
'userId'
},
name
:
{
type
:
DataTypes
.
STRING
,
field
:
'full_name'
...
...
@@ -54,7 +61,7 @@ describe(Support.getTestDialectTeaser("Model"), function () {
return
Promise
.
all
([
queryInterface
.
createTable
(
'users'
,
{
i
d
:
{
userI
d
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
,
primaryKey
:
true
,
...
...
@@ -78,7 +85,7 @@ describe(Support.getTestDialectTeaser("Model"), function () {
type
:
DataTypes
.
STRING
}
})
])
])
;
});
it
(
'should create, fetch and update with alternative field names from a simple model'
,
function
()
{
...
...
@@ -101,7 +108,7 @@ describe(Support.getTestDialectTeaser("Model"), function () {
});
}).
then
(
function
(
user
)
{
expect
(
user
.
get
(
'name'
)).
to
.
equal
(
'Barfoo'
);
})
})
;
});
it
(
'should work with attributes and where on includes'
,
function
()
{
...
...
@@ -139,8 +146,8 @@ describe(Support.getTestDialectTeaser("Model"), function () {
}
});
}).
then
(
function
(
user
)
{
expect
(
user
).
to
.
be
.
ok
})
expect
(
user
).
to
.
be
.
ok
;
})
;
});
it
(
'should work with bulkCreate and findAll'
,
function
()
{
...
...
@@ -155,17 +162,17 @@ describe(Support.getTestDialectTeaser("Model"), function () {
return
self
.
User
.
findAll
();
}).
then
(
function
(
users
)
{
users
.
forEach
(
function
(
user
)
{
expect
([
'Abc'
,
'Bcd'
,
'Cde'
].
indexOf
(
user
.
get
(
'name'
))
!==
-
1
).
to
.
be
.
true
expect
([
'Abc'
,
'Bcd'
,
'Cde'
].
indexOf
(
user
.
get
(
'name'
))
!==
-
1
).
to
.
be
.
true
;
});
});
});
})
})
;
describe
(
'types'
,
function
()
{
describe
(
'VIRTUAL'
,
function
()
{
it
(
'should be ignored in create, updateAttributes and find'
);
it
(
'should be ignored in bulkCreate and findAll'
);
})
})
})
})
\ No newline at end of file
});
});
});
});
\ No newline at end of file
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