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 1e1ef9a5
authored
Oct 26, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed has_many association for tables with identical prefix
1 parent
ad14a7b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
27 deletions
lib/sequelize/utils.js
spec/model-definition.spec.js
lib/sequelize/utils.js
View file @
1e1ef9a
...
@@ -129,10 +129,7 @@ var Utils = module.exports = {
...
@@ -129,10 +129,7 @@ var Utils = module.exports = {
return
result
return
result
},
},
combineTableNames
:
function
(
tableName1
,
tableName2
)
{
combineTableNames
:
function
(
tableName1
,
tableName2
)
{
var
chars1
=
Utils
.
_
.
chars
(
tableName1
.
toLowerCase
())
return
(
tableName1
.
toLowerCase
()
<
tableName2
.
toLowerCase
())
?
(
tableName1
+
tableName2
)
:
(
tableName2
+
tableName1
)
,
chars2
=
Utils
.
_
.
chars
(
tableName2
.
toLowerCase
())
return
(
chars1
[
0
]
<
chars2
[
0
])
?
(
tableName1
+
tableName2
)
:
(
tableName2
+
tableName1
)
},
},
singularize
:
function
(
s
)
{
singularize
:
function
(
s
)
{
return
Utils
.
Lingo
.
en
.
isSingular
(
s
)
?
s
:
Utils
.
Lingo
.
en
.
singularize
(
s
)
return
Utils
.
Lingo
.
en
.
isSingular
(
s
)
?
s
:
Utils
.
Lingo
.
en
.
singularize
(
s
)
...
...
spec/model-definition.spec.js
View file @
1e1ef9a
var
should
=
require
(
"should"
)
var
config
=
require
(
"./config/config"
)
,
config
=
require
(
"./config/config"
)
,
Helpers
=
require
(
"./config/helpers"
)
,
Helpers
=
require
(
"./config/helpers"
)
,
Sequelize
=
require
(
"../index"
)
,
Sequelize
=
require
(
"../index"
)
...
@@ -7,52 +6,49 @@ describe('ModelDefinition', function() {
...
@@ -7,52 +6,49 @@ describe('ModelDefinition', function() {
var
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
var
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
User
=
sequelize
.
define
(
'User'
,
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
,
User
=
sequelize
.
define
(
'User'
,
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
beforeEach
(
function
()
{
Helpers
.
async
(
function
(
done
)
{
sequelize
.
sync
({
force
:
true
}).
on
(
'success'
,
done
).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
})
afterEach
(
function
()
{
afterEach
(
function
()
{
Helpers
.
async
(
function
(
done
)
{
Helpers
.
async
(
function
(
done
)
{
sequelize
.
drop
().
on
(
'success'
,
done
).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
sequelize
.
drop
().
on
(
'success'
,
done
).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
})
})
})
//////////// all //////////////
describe
(
'.all'
,
function
()
{
describe
(
'.all'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
var
createUser
=
function
(
num
,
cb
)
{
var
UserFactory
=
function
(
options
,
callback
,
count
)
{
console
.
log
(
'create user'
)
count
=
count
||
1
User
.
create
({
name
:
'user'
+
num
,
bio
:
'foobar'
}).
on
(
'success'
,
function
(
user
){
--
num
?
createUser
(
num
,
cb
)
:
cb
()
User
.
create
(
options
).
on
(
'success'
,
function
(
user
){
--
count
?
UserFactory
(
options
,
callback
,
count
)
:
callback
(
user
)
}).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
}
}
Helpers
.
async
(
function
(
done
)
{
UserFactory
({
name
:
'user'
,
bio
:
'foobar'
},
done
,
2
)
})
Helpers
.
async
(
function
(
done
)
{
User
.
sync
({
force
:
true
})
.
on
(
'success'
,
function
()
{
done
()
})
.
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
Helpers
.
async
(
function
(
done
)
{
createUser
(
2
,
done
)
})
})
})
it
(
"should return all users"
,
function
()
{
it
(
"should return all users"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
Helpers
.
async
(
function
(
done
)
{
User
.
all
.
on
(
'success'
,
function
(
users
)
{
User
.
all
.
on
(
'success'
,
function
(
users
)
{
done
()
done
()
expect
(
users
.
length
).
toEqual
(
2
)
expect
(
users
.
length
).
toEqual
(
2
)
}).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
}).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
})
})
})
})
})
/////////// create ////////////
describe
(
'.create with options'
,
function
()
{
describe
(
'.create with options'
,
function
()
{
var
Person
=
sequelize
.
define
(
'Person'
,
{
name
:
Sequelize
.
STRING
,
options
:
Sequelize
.
TEXT
})
var
Person
=
sequelize
.
define
(
'Person'
,
{
name
:
Sequelize
.
STRING
,
options
:
Sequelize
.
TEXT
})
beforeEach
(
function
()
{
Helpers
.
async
(
function
(
done
)
{
Person
.
sync
({
force
:
true
})
.
on
(
'success'
,
function
()
{
done
()
})
.
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
})
it
(
'should allow the creation of an object with options as attribute'
,
function
()
{
it
(
'should allow the creation of an object with options as attribute'
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
Helpers
.
async
(
function
(
done
)
{
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
})
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
})
...
@@ -63,4 +59,23 @@ describe('ModelDefinition', function() {
...
@@ -63,4 +59,23 @@ describe('ModelDefinition', function() {
})
})
})
})
})
})
/////////// many-to-many with same prefix ////////////
describe
(
'many-to-many'
,
function
()
{
describe
(
'where tables have the same prefix'
,
function
()
{
var
Table2
=
sequelize
.
define
(
'wp_table2'
,
{
foo
:
Sequelize
.
STRING
})
,
Table1
=
sequelize
.
define
(
'wp_table1'
,
{
foo
:
Sequelize
.
STRING
})
Table1
.
hasMany
(
Table2
)
Table2
.
hasMany
(
Table1
)
it
(
"should create a table wp_table1wp_table2s"
,
function
()
{
var
models
=
sequelize
.
modelManager
.
models
.
filter
(
function
(
model
)
{
return
model
.
tableName
.
indexOf
(
'wp_table1swp_table2s'
)
>
-
1
})
expect
(
models
.
length
).
toBe
(
1
)
})
})
})
})
})
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