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
不要怂,就是干,撸起袖子干!
You need to sign in or sign up before continuing.
Commit c7592d70
authored
Sep 17, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added method for fetching associated data
1 parent
f5c504a6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
1 deletions
examples/LoadAssociatedData/app.js
lib/sequelize/Helper.js
lib/sequelize/SequelizeTable.js
examples/LoadAssociatedData/app.js
0 → 100644
View file @
c7592d7
File mode changed
lib/sequelize/Helper.js
View file @
c7592d7
...
@@ -14,6 +14,10 @@ exports.Helper = function(Sequelize) {
...
@@ -14,6 +14,10 @@ exports.Helper = function(Sequelize) {
},
},
SQL
:
{
SQL
:
{
isManyToManyAssociation
:
function
(
association
)
{
return
([
'hasMany'
,
'hasAndBelongsToMany'
].
indexOf
(
association
.
type
)
>
-
1
)
},
manyToManyTableName
:
function
(
name1
,
name2
)
{
manyToManyTableName
:
function
(
name1
,
name2
)
{
var
_name1
=
name1
[
0
].
toUpperCase
()
+
name1
.
replace
(
/^./
,
""
)
var
_name1
=
name1
[
0
].
toUpperCase
()
+
name1
.
replace
(
/^./
,
""
)
var
_name2
=
name2
[
0
].
toUpperCase
()
+
name2
.
replace
(
/^./
,
""
)
var
_name2
=
name2
[
0
].
toUpperCase
()
+
name2
.
replace
(
/^./
,
""
)
...
...
lib/sequelize/SequelizeTable.js
View file @
c7592d7
...
@@ -217,7 +217,8 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
...
@@ -217,7 +217,8 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
Factory
.
addOneToOneMethods
(
_table
,
table
,
assocName
,
backAssociation
.
name
)
Factory
.
addOneToOneMethods
(
_table
,
table
,
assocName
,
backAssociation
.
name
)
}
}
backAssociation
.
name
=
assocName
// TODO: check if the following line is not needed; specs r failing
// backAssociation.name = assocName
// end - overwrite the association of the before defined hasOne or hasMany relation, to fit the belongsTo foreign keys
// 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'
})
table
.
associations
.
push
({
name
:
assocName
,
table
:
_table
,
type
:
'belongsTo'
})
...
@@ -286,6 +287,29 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
...
@@ -286,6 +287,29 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
return
this
.
id
==
null
return
this
.
id
==
null
},
},
loadAssociatedData
:
function
(
callback
)
{
var
associatedData
=
{},
self
=
this
,
setAssociatedDataAndReturn
=
function
()
{
self
.
associatedData
=
associatedData
if
(
callback
)
callback
(
associatedData
)
}
if
(
this
.
table
.
associations
.
length
==
0
)
setAssociatedDataAndReturn
()
else
this
.
table
.
associations
.
forEach
(
function
(
association
)
{
var
isManyToManyAssociation
=
Sequelize
.
Helper
.
SQL
.
isManyToManyAssociation
(
association
),
getter
=
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'get'
,
association
.
name
,
!
isManyToManyAssociation
)
self
[
getter
](
function
(
objects
)
{
associatedData
[
association
.
name
]
=
objects
if
(
Sequelize
.
Helper
.
Hash
.
keys
(
associatedData
).
length
==
self
.
table
.
associations
.
length
)
setAssociatedDataAndReturn
()
})
})
},
save
:
function
(
callback
)
{
save
:
function
(
callback
)
{
var
query
=
null
,
var
query
=
null
,
self
=
this
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