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 6a46e603
authored
Mar 21, 2012
by
Ross Grayton
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/sdepold/sequelize
2 parents
969f7a35
38135327
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
2 deletions
changelog.md
lib/dialects/mysql/connector-manager.js
spec/associations/has-many.spec.js
changelog.md
View file @
6a46e60
# v1.3.7 #
# v1.3.7 #
-
[
BUG
]
fixed issue where multiple belongsTo or hasOne associations to the same table overwrite each other
-
[
BUG
]
fixed issue where multiple belongsTo or hasOne associations to the same table overwrite each other
-
[
BUG
]
fixed memory leaks (thanks to megshark)
# v1.3.6 #
# v1.3.6 #
-
[
BUG
]
don't update an existing updatedAt-attribute if timestamps option for a DAO is false
-
[
BUG
]
don't update an existing updatedAt-attribute if timestamps option for a DAO is false
...
...
lib/dialects/mysql/connector-manager.js
View file @
6a46e60
...
@@ -14,6 +14,8 @@ module.exports = (function() {
...
@@ -14,6 +14,8 @@ module.exports = (function() {
}
}
Utils
.
_
.
extend
(
ConnectorManager
.
prototype
,
require
(
"../connector-manager"
).
prototype
)
Utils
.
_
.
extend
(
ConnectorManager
.
prototype
,
require
(
"../connector-manager"
).
prototype
)
var
isConnecting
=
false
ConnectorManager
.
prototype
.
query
=
function
(
sql
,
callee
,
options
)
{
ConnectorManager
.
prototype
.
query
=
function
(
sql
,
callee
,
options
)
{
if
(
!
this
.
isConnected
)
this
.
connect
()
if
(
!
this
.
isConnected
)
this
.
connect
()
...
@@ -29,7 +31,10 @@ module.exports = (function() {
...
@@ -29,7 +31,10 @@ module.exports = (function() {
ConnectorManager
.
prototype
.
connect
=
function
()
{
ConnectorManager
.
prototype
.
connect
=
function
()
{
var
self
=
this
var
self
=
this
// in case database is slow to connect, prevent orphaning the client
if
(
this
.
isConnecting
)
{
return
}
this
.
client
=
require
(
"mysql"
).
createClient
({
this
.
client
=
require
(
"mysql"
).
createClient
({
user
:
this
.
config
.
username
,
user
:
this
.
config
.
username
,
password
:
this
.
config
.
password
,
password
:
this
.
config
.
password
,
...
@@ -39,11 +44,27 @@ module.exports = (function() {
...
@@ -39,11 +44,27 @@ module.exports = (function() {
})
})
this
.
client
.
setMaxListeners
(
this
.
maxConcurrentQueries
)
this
.
client
.
setMaxListeners
(
this
.
maxConcurrentQueries
)
this
.
isConnecting
=
false
}
}
ConnectorManager
.
prototype
.
disconnect
=
function
()
{
ConnectorManager
.
prototype
.
disconnect
=
function
()
{
var
self
=
this
var
self
=
this
this
.
client
.
end
(
function
()
{
self
.
client
=
null
})
this
.
client
.
end
(
function
()
{
var
intervalObj
=
null
var
cleanup
=
function
()
{
var
retryCt
=
0
// make sure to let client finish before calling destroy
if
(
!
self
.
hasNoConnections
)
{
return
}
// needed to prevent mysql connection leak
self
.
client
.
destroy
()
self
.
client
=
null
clearInterval
(
intervalObj
)
}
intervalObj
=
setInterval
(
cleanup
,
10
)
cleanup
()
})
}
}
// private
// private
...
...
spec/associations/has-many.spec.js
View file @
6a46e60
...
@@ -278,6 +278,49 @@ describe('HasMany', function() {
...
@@ -278,6 +278,49 @@ describe('HasMany', function() {
})
})
})
})
it
(
"allows join table to be mapped and specified"
,
function
()
{
var
User
=
sequelize
.
define
(
'User'
,
{
name
:
Sequelize
.
STRING
},
{
underscore
:
true
,
freezeTableName
:
true
})
var
Company
=
sequelize
.
define
(
'Company'
,
{
name
:
Sequelize
.
STRING
},
{
underscore
:
true
,
freezeTableName
:
true
})
var
CompanyAccess
=
sequelize
.
define
(
'CompanyAccess'
,
{
company_id
:
Sequelize
.
INTEGER
,
user_id
:
Sequelize
.
INTEGER
,
permission
:
Sequelize
.
STRING
},
{
underscore
:
true
,
freezeTableName
:
true
})
CompanyAccess
.
belongsTo
(
User
,
{
as
:
'User'
,
foreignKey
:
'user_id'
})
CompanyAccess
.
belongsTo
(
Company
,
{
as
:
'Company'
,
foreignKey
:
'company_id'
})
User
.
hasMany
(
Company
,
{
as
:
'Companies'
,
foreignKey
:
'user_id'
,
joinTableName
:
'CompanyAccess'
})
Company
.
hasMany
(
User
,
{
as
:
'Users'
,
foreignKey
:
'company_id'
,
joinTableName
:
'CompanyAccess'
})
Helpers
.
async
(
function
(
done
)
{
var
companies
=
[]
CompanyAccess
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
sync
({
force
:
true
}).
success
(
function
()
{
Company
.
sync
({
force
:
true
}).
success
(
function
()
{
Company
.
create
({
name
:
'IBM'
}).
success
(
function
(
ibm
)
{
companies
.
push
(
ibm
)
Company
.
create
({
name
:
'EA'
}).
success
(
function
(
ea
)
{
companies
.
push
(
ea
)
User
.
create
({
name
:
'joe@ibm.com'
}).
success
(
function
(
joe
)
{
joe
.
setCompanies
(
companies
).
success
(
function
(){
User
.
find
({
where
:
{
name
:
'joe@ibm.com'
}}).
success
(
function
(
joe
)
{
expect
(
joe
).
not
.
toEqual
(
null
)
joe
.
getCompanies
().
success
(
function
(
comps
)
{
expect
(
comps
).
not
.
toEqual
(
null
)
expect
(
comps
.
length
).
toEqual
(
2
)
done
()
})
})
})
})
})
})
})
})
})
})
})
it
(
"gets and sets the connector daos"
,
function
()
{
it
(
"gets and sets the connector daos"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
Helpers
.
async
(
function
(
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