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 ed1e6235
authored
Oct 14, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into milestones/2.0.0
2 parents
0dc5ac32
19828b24
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
8 deletions
lib/dao-factory.js
test/dao-factory.test.js
test/dao.test.js
test/hooks.test.js
test/mysql/connector-manager.test.js
test/support.js
lib/dao-factory.js
View file @
ed1e623
...
@@ -1084,7 +1084,10 @@ module.exports = (function() {
...
@@ -1084,7 +1084,10 @@ module.exports = (function() {
if
(
include
.
hasOwnProperty
(
'attributes'
))
{
if
(
include
.
hasOwnProperty
(
'attributes'
))
{
var
primaryKeys
;
var
primaryKeys
;
if
(
include
.
daoFactory
.
hasPrimaryKeys
)
{
if
(
include
.
daoFactory
.
hasPrimaryKeys
)
{
primaryKeys
=
include
.
daoFactory
.
primaryKeys
primaryKeys
=
[]
for
(
var
field_name
in
include
.
daoFactory
.
primaryKeys
)
{
primaryKeys
.
push
(
field_name
)
}
}
else
{
}
else
{
primaryKeys
=
[
'id'
]
primaryKeys
=
[
'id'
]
}
}
...
...
test/dao-factory.test.js
View file @
ed1e623
...
@@ -2056,6 +2056,61 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -2056,6 +2056,61 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
'getting parent data in many to one relationship'
,
function
(
done
)
{
var
self
=
this
;
var
User
=
self
.
sequelize
.
define
(
'User'
,
{
id
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
},
username
:
{
type
:
Sequelize
.
STRING
}
})
var
Message
=
self
.
sequelize
.
define
(
'Message'
,
{
id
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
},
user_id
:
{
type
:
Sequelize
.
INTEGER
},
message
:
{
type
:
Sequelize
.
STRING
}
})
User
.
hasMany
(
Message
)
Message
.
belongsTo
(
User
,
{
foreignKey
:
'user_id'
})
Message
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'test_testerson'
}).
success
(
function
(
user
)
{
Message
.
create
({
user_id
:
user
.
id
,
message
:
'hi there!'
}).
success
(
function
(
message
)
{
Message
.
create
({
user_id
:
user
.
id
,
message
:
'a second message'
}).
success
(
function
(
message
)
{
Message
.
findAll
({
where
:
{
user_id
:
user
.
id
},
attributes
:
[
'user_id'
,
'message'
],
include
:
[{
model
:
User
,
as
:
User
.
tableName
,
attributes
:
[
'username'
]
}]
}).
success
(
function
(
messages
)
{
expect
(
messages
.
length
).
to
.
equal
(
2
);
expect
(
messages
[
0
].
message
).
to
.
equal
(
'hi there!'
);
expect
(
messages
[
0
].
user
.
username
).
to
.
equal
(
'test_testerson'
);
expect
(
messages
[
1
].
message
).
to
.
equal
(
'a second message'
);
expect
(
messages
[
1
].
user
.
username
).
to
.
equal
(
'test_testerson'
);
done
()
})
})
})
})
})
})
})
it
(
'allows mulitple assocations of the same model with different alias'
,
function
(
done
)
{
it
(
'allows mulitple assocations of the same model with different alias'
,
function
(
done
)
{
var
self
=
this
var
self
=
this
...
@@ -3570,8 +3625,6 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -3570,8 +3625,6 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
describe
(
'references'
,
function
()
{
describe
(
'references'
,
function
()
{
this
.
timeout
(
3000
)
beforeEach
(
function
(
done
)
{
beforeEach
(
function
(
done
)
{
var
self
=
this
var
self
=
this
...
...
test/dao.test.js
View file @
ed1e623
...
@@ -13,6 +13,8 @@ chai.use(datetime)
...
@@ -13,6 +13,8 @@ chai.use(datetime)
chai
.
Assertion
.
includeStack
=
true
chai
.
Assertion
.
includeStack
=
true
describe
(
Support
.
getTestDialectTeaser
(
"DAO"
),
function
()
{
describe
(
Support
.
getTestDialectTeaser
(
"DAO"
),
function
()
{
this
.
timeout
(
10000
)
beforeEach
(
function
(
done
)
{
beforeEach
(
function
(
done
)
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
{
type
:
DataTypes
.
STRING
},
username
:
{
type
:
DataTypes
.
STRING
},
...
@@ -449,7 +451,6 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -449,7 +451,6 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
it
(
"should update read only attributes as well (updatedAt)"
,
function
(
done
)
{
it
(
"should update read only attributes as well (updatedAt)"
,
function
(
done
)
{
var
self
=
this
var
self
=
this
this
.
timeout
=
2000
this
.
User
.
create
({
username
:
'John Doe'
}).
complete
(
function
(
err
,
originalUser
)
{
this
.
User
.
create
({
username
:
'John Doe'
}).
complete
(
function
(
err
,
originalUser
)
{
var
originallyUpdatedAt
=
originalUser
.
updatedAt
var
originallyUpdatedAt
=
originalUser
.
updatedAt
...
@@ -565,8 +566,6 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -565,8 +566,6 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
})
describe
(
'save'
,
function
()
{
describe
(
'save'
,
function
()
{
this
.
timeout
(
3000
)
// for update timestamp
it
(
'only updates fields in passed array'
,
function
(
done
)
{
it
(
'only updates fields in passed array'
,
function
(
done
)
{
var
self
=
this
var
self
=
this
,
userId
=
null
,
userId
=
null
...
...
test/hooks.test.js
View file @
ed1e623
...
@@ -8,6 +8,8 @@ var chai = require('chai')
...
@@ -8,6 +8,8 @@ var chai = require('chai')
chai
.
Assertion
.
includeStack
=
true
chai
.
Assertion
.
includeStack
=
true
describe
(
Support
.
getTestDialectTeaser
(
"Hooks"
),
function
()
{
describe
(
Support
.
getTestDialectTeaser
(
"Hooks"
),
function
()
{
this
.
timeout
(
10000
)
describe
(
'#validate'
,
function
()
{
describe
(
'#validate'
,
function
()
{
describe
(
'via define'
,
function
()
{
describe
(
'via define'
,
function
()
{
describe
(
'on success'
,
function
()
{
describe
(
'on success'
,
function
()
{
...
...
test/mysql/connector-manager.test.js
View file @
ed1e623
...
@@ -9,8 +9,6 @@ chai.Assertion.includeStack = true
...
@@ -9,8 +9,6 @@ chai.Assertion.includeStack = true
if
(
dialect
.
match
(
/^mysql/
))
{
if
(
dialect
.
match
(
/^mysql/
))
{
describe
(
'[MYSQL Specific] Connector Manager'
,
function
()
{
describe
(
'[MYSQL Specific] Connector Manager'
,
function
()
{
this
.
timeout
(
10000
)
it
(
'works correctly after being idle'
,
function
(
done
)
{
it
(
'works correctly after being idle'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
})
,
spy
=
sinon
.
spy
()
,
spy
=
sinon
.
spy
()
...
...
test/support.js
View file @
ed1e623
...
@@ -128,6 +128,7 @@ before(function(done) {
...
@@ -128,6 +128,7 @@ before(function(done) {
beforeEach
(
function
(
done
)
{
beforeEach
(
function
(
done
)
{
this
.
sequelize
=
sequelize
this
.
sequelize
=
sequelize
Support
.
clearDatabase
(
this
.
sequelize
,
function
()
{
Support
.
clearDatabase
(
this
.
sequelize
,
function
()
{
done
()
done
()
})
})
...
...
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