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 124920a6
authored
Mar 12, 2012
by
Meg Sharkey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added test
1 parent
9ef6a23c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
6 deletions
package.json
spec/associations/has-many.spec.js
spec/config/config.js
package.json
View file @
124920a
{
"name"
:
"s
eque
lize"
,
"name"
:
"s
q
lize"
,
"description"
:
"MySQL ORM for Node.JS"
,
"version"
:
"1.3.2"
,
"version"
:
"1.3.2
-1
"
,
"author"
:
"Sascha Depold <sascha@depold.com>"
,
"contributors"
:
[
{
"name"
:
"Sascha Depold"
,
"email"
:
"sascha@depold.com"
},
...
...
@@ -20,7 +20,7 @@
"jasmine-node"
:
"1.0.x"
,
"sqlite3"
:
">=2.0.0"
},
"keywords"
:
[
"mysql"
,
"orm"
,
"nodejs"
,
"object relational mapper"
],
"keywords"
:
[],
"main"
:
"index"
,
"scripts"
:
{},
"bin"
:
{
...
...
spec/associations/has-many.spec.js
View file @
124920a
...
...
@@ -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 models"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
...
...
spec/config/config.js
View file @
124920a
module
.
exports
=
{
username
:
"root"
,
password
:
null
,
database
:
'sequelize_test'
,
username
:
'meg'
,
//
"root",
password
:
'meg'
,
//
null,
database
:
'
test'
,
//'
sequelize_test',
host
:
'127.0.0.1'
,
rand
:
function
()
{
return
parseInt
(
Math
.
random
()
*
999
)
...
...
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