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 5162c970
authored
Sep 09, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first steps for getting one to many assocs run again
1 parent
d23453be
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
20 deletions
lib/sequelize/SequelizeTable.js
lib/sequelize/SequelizeTable.js
View file @
5162c97
...
@@ -136,13 +136,9 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
...
@@ -136,13 +136,9 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
hasMany
:
function
(
assocName
,
_table
,
backAssocName
)
{
hasMany
:
function
(
assocName
,
_table
,
backAssocName
)
{
var
Factory
=
new
require
(
"./Factory"
).
Factory
(
Sequelize
,
sequelize
)
var
Factory
=
new
require
(
"./Factory"
).
Factory
(
Sequelize
,
sequelize
)
var
association
=
{
name
:
assocName
,
backAssociationName
:
backAssocName
,
table
:
_table
,
type
:
'hasMany'
}
table
.
associations
.
push
({
table
.
associations
.
push
(
association
)
name
:
assocName
,
backAssociationName
:
backAssocName
,
table
:
_table
,
type
:
'hasMany'
})
// don't check inside of method to increase performance
// don't check inside of method to increase performance
if
(
backAssocName
)
{
if
(
backAssocName
)
{
...
@@ -155,7 +151,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
...
@@ -155,7 +151,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
table
.
prototype
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'set'
,
assocName
)]
=
Factory
.
createOneToManySetter
(
table
,
assocName
)
table
.
prototype
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'set'
,
assocName
)]
=
Factory
.
createOneToManySetter
(
table
,
assocName
)
}
}
return
table
return
association
},
},
hasOne
:
function
(
assocName
,
_table
)
{
hasOne
:
function
(
assocName
,
_table
)
{
...
@@ -195,23 +191,30 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
...
@@ -195,23 +191,30 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
return
table
return
table
},
},
belongsTo
:
function
(
assocName
,
_table
)
{
belongsTo
:
function
(
assocName
,
_table
,
backAssociation
)
{
table
.
associations
.
push
({
if
(
typeof
backAssociation
==
'undefined'
)
name
:
assocName
,
throw
new
Error
(
"Calling belongsTo with only two parameters is deprecated! Please take a look at the example in the repository!"
)
table
:
_table
,
type
:
'belongsTo'
// this will overwrite the association name of the before defined hasOne or hasMany relation
})
backAssociation
.
name
=
assocName
table
.
associations
.
push
({
name
:
assocName
,
table
:
_table
,
type
:
'belongsTo'
})
// getter
table
.
prototype
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'get'
,
assocName
)]
=
function
(
callback
)
{
table
.
prototype
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'get'
,
assocName
)]
=
function
(
callback
)
{
if
((
this
[
_table
.
identifier
]
==
null
)
||
(
isNaN
(
this
[
_table
.
identifier
]))
)
var
identifier
=
Sequelize
.
Helper
.
SQL
.
asTableIdentifier
(
assocName
)
callback
([])
else
if
((
this
[
identifier
]
==
null
)
||
(
isNaN
(
this
[
identifier
])))
callback
([])
_table
.
find
(
this
[
_table
.
identifier
],
callback
)
else
_table
.
find
(
this
[
identifier
],
callback
)
}
}
table
.
prototype
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'set'
,
assocName
)]
=
function
(
object
,
callback
)
{
// setter
var
attr
=
{};
attr
[
object
.
table
.
identifier
]
=
object
.
id
table
.
prototype
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'set'
,
assocName
,
true
)]
=
function
(
object
,
callback
)
{
var
self
=
this
var
attr
=
{},
self
=
this
attr
[
Sequelize
.
Helper
.
SQL
.
asTableIdentifier
(
assocName
)]
=
object
.
id
this
.
updateAttributes
(
attr
,
function
()
{
this
.
updateAttributes
(
attr
,
function
()
{
self
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'get'
,
assocName
)](
callback
)
self
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'get'
,
assocName
)](
callback
)
})
})
...
...
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