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 524870df
authored
Oct 01, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'foreignnamefix' of
https://github.com/durango/sequelize
into durango-foreignnamefix
2 parents
5c831f16
59497ddf
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
14 deletions
lib/associations/helpers.js
lib/dialects/postgres/query-generator.js
test/associations/has-many.test.js
test/dao-factory.test.js
lib/associations/helpers.js
View file @
524870d
...
@@ -13,10 +13,21 @@ module.exports = {
...
@@ -13,10 +13,21 @@ module.exports = {
return
source
.
rawAttributes
[
key
].
primaryKey
return
source
.
rawAttributes
[
key
].
primaryKey
})
})
if
(
primaryKeys
.
length
==
1
)
{
if
(
primaryKeys
.
length
===
1
)
{
newAttribute
.
references
=
source
.
tableName
,
if
(
!!
source
.
options
.
schema
)
{
newAttribute
.
references
=
source
.
daoFactoryManager
.
sequelize
.
queryInterface
.
QueryGenerator
.
addSchema
({
tableName
:
source
.
tableName
,
options
:
{
schema
:
source
.
options
.
schema
,
schemaDelimiter
:
source
.
options
.
schemaDelimiter
}
})
}
else
{
newAttribute
.
references
=
source
.
tableName
}
newAttribute
.
referencesKey
=
primaryKeys
[
0
]
newAttribute
.
referencesKey
=
primaryKeys
[
0
]
newAttribute
.
onDelete
=
options
.
onDelete
,
newAttribute
.
onDelete
=
options
.
onDelete
newAttribute
.
onUpdate
=
options
.
onUpdate
newAttribute
.
onUpdate
=
options
.
onUpdate
}
}
}
}
...
...
lib/dialects/postgres/query-generator.js
View file @
524870d
...
@@ -15,7 +15,7 @@ module.exports = (function() {
...
@@ -15,7 +15,7 @@ module.exports = (function() {
var
schema
=
(
!!
opts
.
options
&&
!!
opts
.
options
.
schema
?
opts
.
options
.
schema
:
undefined
)
var
schema
=
(
!!
opts
.
options
&&
!!
opts
.
options
.
schema
?
opts
.
options
.
schema
:
undefined
)
var
schemaDelimiter
=
(
!!
opts
.
options
&&
!!
opts
.
options
.
schemaDelimiter
?
opts
.
options
.
schemaDelimiter
:
undefined
)
var
schemaDelimiter
=
(
!!
opts
.
options
&&
!!
opts
.
options
.
schemaDelimiter
?
opts
.
options
.
schemaDelimiter
:
undefined
)
if
(
!!
opts
.
tableName
)
{
if
(
!!
opts
&&
!!
opts
.
tableName
)
{
tableName
=
opts
.
tableName
tableName
=
opts
.
tableName
}
}
else
if
(
typeof
opts
===
"string"
)
{
else
if
(
typeof
opts
===
"string"
)
{
...
@@ -26,7 +26,7 @@ module.exports = (function() {
...
@@ -26,7 +26,7 @@ module.exports = (function() {
return
tableName
return
tableName
}
}
return
this
.
quoteIdentifier
(
schema
)
+
'.'
+
this
.
quoteIdentifier
(
tableName
)
return
this
.
quoteIdentifier
s
((
!!
schema
?
(
schema
+
'.'
+
tableName
)
:
tableName
));
},
},
createSchema
:
function
(
schema
)
{
createSchema
:
function
(
schema
)
{
...
@@ -665,10 +665,10 @@ module.exports = (function() {
...
@@ -665,10 +665,10 @@ module.exports = (function() {
if
(
dataType
.
references
)
{
if
(
dataType
.
references
)
{
template
+=
" REFERENCES <%= referencesTable %> (<%= referencesKey %>)"
template
+=
" REFERENCES <%= referencesTable %> (<%= referencesKey %>)"
replacements
.
referencesTable
=
this
.
quoteIdentifier
(
dataType
.
references
)
replacements
.
referencesTable
=
this
.
quoteIdentifier
s
(
dataType
.
references
)
if
(
dataType
.
referencesKey
)
{
if
(
dataType
.
referencesKey
)
{
replacements
.
referencesKey
=
this
.
quoteIdentifier
(
dataType
.
referencesKey
)
replacements
.
referencesKey
=
this
.
quoteIdentifier
s
(
dataType
.
referencesKey
)
}
else
{
}
else
{
replacements
.
referencesKey
=
this
.
quoteIdentifier
(
'id'
)
replacements
.
referencesKey
=
this
.
quoteIdentifier
(
'id'
)
}
}
...
...
test/associations/has-many.test.js
View file @
524870d
...
@@ -592,7 +592,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -592,7 +592,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
this
.
User
.
hasMany
(
this
.
Project
,
{
joinTableModel
:
this
.
UserProjects
})
this
.
User
.
hasMany
(
this
.
Project
,
{
joinTableModel
:
this
.
UserProjects
})
this
.
Project
.
hasMany
(
this
.
User
,
{
joinTableModel
:
this
.
UserProjects
})
this
.
Project
.
hasMany
(
this
.
User
,
{
joinTableModel
:
this
.
UserProjects
})
this
.
sequelize
.
sync
().
success
(
function
()
{
done
()
})
this
.
sequelize
.
sync
().
success
(
function
()
{
done
()
})
})
})
...
@@ -614,7 +614,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -614,7 +614,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
done
()
done
()
})
})
})
})
})
})
})
})
})
})
...
@@ -635,13 +635,13 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -635,13 +635,13 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
done
()
done
()
})
})
})
})
})
})
})
})
})
})
})
})
describe
(
'inserting in join table'
,
function
()
{
describe
(
'inserting in join table'
,
function
()
{
describe
(
'add'
,
function
()
{
describe
(
'add'
,
function
()
{
it
(
'should insert data provided on the object into the join table'
,
function
(
done
)
{
it
(
'should insert data provided on the object into the join table'
,
function
(
done
)
{
...
@@ -658,7 +658,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -658,7 +658,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
done
()
done
()
})
})
})
})
})
})
})
})
})
})
...
@@ -672,7 +672,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -672,7 +672,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
done
()
done
()
})
})
})
})
})
})
})
})
})
})
})
})
...
@@ -704,7 +704,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -704,7 +704,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
})
})
})
})
})
})
})
})
})
})
})
})
})
...
...
test/dao-factory.test.js
View file @
524870d
...
@@ -3491,6 +3491,44 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -3491,6 +3491,44 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
'should be able to reference a table with a schema set'
,
function
(
done
)
{
var
self
=
this
var
sequelize
=
this
.
sequelize
var
UserPub
=
this
.
sequelize
.
define
(
'UserPub'
,
{
username
:
Sequelize
.
STRING
},
{
schema
:
'prefix'
})
var
ItemPub
=
this
.
sequelize
.
define
(
'ItemPub'
,
{
name
:
Sequelize
.
STRING
},
{
schema
:
'prefix'
})
UserPub
.
hasMany
(
ItemPub
,
{
foreignKeyConstraint
:
true
})
var
run
=
function
()
{
UserPub
.
sync
({
force
:
true
}).
success
(
function
()
{
ItemPub
.
sync
({
force
:
true
}).
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
"postgres"
)
{
expect
(
sql
).
to
.
match
(
/REFERENCES
\s
+"prefix"
\.
"UserPubs"
\(
"id"
\)
/
)
}
else
{
expect
(
sql
).
to
.
match
(
/REFERENCES
\s
+`prefix
\.
UserPubs`
\(
`id`
\)
/
)
}
done
()
})
})
}
if
(
dialect
===
"postgres"
)
{
this
.
sequelize
.
queryInterface
.
createSchema
(
'prefix'
).
success
(
function
()
{
run
.
call
(
self
)
})
}
else
{
run
.
call
(
self
)
}
})
it
(
"should be able to create and update records under any valid schematic"
,
function
(
done
){
it
(
"should be able to create and update records under any valid schematic"
,
function
(
done
){
var
self
=
this
var
self
=
this
...
...
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