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 3ca94230
authored
Sep 17, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed some issues on belongsTo
1 parent
5c1ea45c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
16 deletions
lib/sequelize/Factory.js
lib/sequelize/SequelizeTable.js
test/SequelizeHelperTest.js
test/SequelizeTableTest.js
lib/sequelize/Factory.js
View file @
3ca9423
...
...
@@ -14,8 +14,8 @@ module.exports.Factory = function(Sequelize, sequelize) {
},
addOneToOneMethods
:
function
(
table1
,
table2
,
assocName
,
backAssocName
)
{
var
setterName
=
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'set'
,
backAssocName
||
assocName
),
getterName
=
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'get'
,
backAssocName
||
assocName
)
var
setterName
=
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'set'
,
backAssocName
||
assocName
,
true
),
getterName
=
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'get'
,
backAssocName
||
assocName
,
true
)
// getter
table1
.
prototype
[
getterName
]
=
function
(
callback
)
{
...
...
@@ -28,7 +28,7 @@ module.exports.Factory = function(Sequelize, sequelize) {
table1
.
prototype
[
setterName
]
=
function
(
object
,
callback
)
{
var
self
=
this
this
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'get'
,
backAssocName
)](
function
(
currentAssociation
)
{
this
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'get'
,
backAssocName
,
true
)](
function
(
currentAssociation
)
{
var
attr
=
{}
if
(
currentAssociation
==
null
)
{
...
...
lib/sequelize/SequelizeTable.js
View file @
3ca9423
...
...
@@ -205,20 +205,19 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
throw
new
Error
(
"Calling belongsTo with only two parameters is deprecated! Please take a look at the example in the repository!"
)
// start - overwrite the association of the before defined hasOne or hasMany relation, to fit the belongsTo foreign keys
var
Factory
=
new
require
(
"./Factory"
).
Factory
(
Sequelize
,
sequelize
)
var
Factory
=
new
require
(
"./Factory"
).
Factory
(
Sequelize
,
sequelize
),
isManyToManyAssociation
=
Sequelize
.
Helper
.
SQL
.
isManyToManyAssociation
(
backAssociation
)
if
(
backAssociation
.
type
==
'hasMany'
)
{
delete
_table
.
prototype
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'get'
,
backAssociation
.
name
)]
delete
_table
.
prototype
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'set'
,
backAssociation
.
name
)]
delete
_table
.
prototype
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'get'
,
backAssociation
.
name
,
!
isManyToManyAssociation
)]
delete
_table
.
prototype
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'set'
,
backAssociation
.
name
,
!
isManyToManyAssociation
)]
if
(
backAssociation
.
type
==
'hasMany'
)
Factory
.
addOneToManyMethods
(
_table
,
table
,
assocName
,
backAssociation
.
name
)
}
else
{
delete
_table
.
prototype
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'get'
,
backAssociation
.
name
)]
delete
_table
.
prototype
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'set'
,
backAssociation
.
name
)]
else
Factory
.
addOneToOneMethods
(
_table
,
table
,
assocName
,
backAssociation
.
name
)
}
// TODO: check if the following line is not needed; specs r failing
// backAssociation.name = assocName
// backAssociation.name = assocName
// end - overwrite the association of the before defined hasOne or hasMany relation, to fit the belongsTo foreign keys
table
.
associations
.
push
({
name
:
assocName
,
table
:
_table
,
type
:
'belongsTo'
})
...
...
test/SequelizeHelperTest.js
View file @
3ca9423
...
...
@@ -69,7 +69,8 @@ module.exports = {
assert
.
equal
(
h
.
SQL
.
hashToWhereConditions
({
name
:
'asd'
},
Day
.
attributes
),
"name='asd'"
)
},
'SQL: addPrefix'
:
function
(
assert
)
{
assert
.
equal
(
h
.
SQL
.
addPrefix
(
'foo'
,
'bar'
),
'fooBar'
)
assert
.
equal
(
h
.
SQL
.
addPrefix
(
'foo'
,
'bar'
,
true
),
'fooBar'
)
assert
.
equal
(
h
.
SQL
.
addPrefix
(
'foo'
,
'bar'
,
false
),
'fooBars'
)
},
'Hash: forEach'
:
function
(
assert
)
{
var
values
=
[]
...
...
test/SequelizeTableTest.js
View file @
3ca9423
...
...
@@ -158,15 +158,15 @@ module.exports = {
var
Day
=
s
.
define
(
'Day2'
,
{
name
:
Sequelize
.
TEXT
})
var
HasOneBlubb
=
s
.
define
(
'HasOneBlubb'
,
{})
Day
.
hasOne
(
'HasOneBlubb'
,
HasOneBlubb
)
assert
.
isDefined
(
new
Day
({
name
:
''
}).
getHasOneBlubb
)
assert
.
isDefined
(
Day
.
prototype
.
getHasOneBlubb
)
},
'hasOne set association'
:
function
(
assert
,
beforeExit
)
{
var
s2
=
new
Sequelize
(
'sequelize_test'
,
'root'
,
null
,
{
disableLogging
:
true
})
var
Task
=
s2
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
var
Deadline
=
s2
.
define
(
'Deadline'
,
{
date
:
Sequelize
.
DATE
})
var
taskAssoc
=
Task
.
hasOne
(
'deadline'
,
Deadline
)
Deadline
.
belongsTo
(
'task'
,
Task
,
taskAssoc
)
Task
.
hasOneAndBelongsTo
(
'deadline'
,
Deadline
,
'task'
)
var
task
=
new
Task
({
title
:
'do smth'
})
var
deadline
=
new
Deadline
({
date
:
new
Date
()})
...
...
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