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 7eeccd0c
authored
Sep 22, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some changes on the example
1 parent
8f0763a1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
14 deletions
examples/fetchAssociations/app.js
examples/fetchAssociations/app.js
View file @
7eeccd0
...
@@ -16,37 +16,50 @@ Sequelize.chainQueries([{drop: sequelize}, {sync: sequelize}], function() {
...
@@ -16,37 +16,50 @@ Sequelize.chainQueries([{drop: sequelize}, {sync: sequelize}], function() {
pet1
=
new
Pet
({
name
:
'Bob'
}),
pet1
=
new
Pet
({
name
:
'Bob'
}),
pet2
=
new
Pet
({
name
:
'Aaron'
})
pet2
=
new
Pet
({
name
:
'Aaron'
})
Sequelize
.
chainQueries
([{
save
:
person
},
{
save
:
pet1
},
{
save
:
pet2
],
function
()
{
Sequelize
.
chainQueries
([{
save
:
person
},
{
save
:
pet1
},
{
save
:
pet2
}
],
function
()
{
person
.
setPets
([
pet1
],
function
(
pets
)
{
person
.
setPets
([
pet1
],
function
(
pets
)
{
console
.
log
(
'my pet: '
+
pets
[
0
].
name
)
console
.
log
(
"Now let's get the same data with fetchData!"
)
Sequelize
.
Helper
.
log
(
'my pet: '
+
pets
[
0
].
name
)
Sequelize
.
Helper
.
log
(
"Now let's get the same data with fetchData!"
)
person
.
fetchAssociations
(
function
(
data
)
{
person
.
fetchAssociations
(
function
(
data
)
{
Sequelize
.
Helper
.
log
(
"And here we are: "
+
data
.
pets
[
0
].
name
)
Sequelize
.
Helper
.
log
(
"And here we are: "
+
data
.
pets
[
0
].
name
)
Sequelize
.
Helper
.
log
(
"The object should now also contain the data: "
+
person
.
fetchedAssociations
.
pets
[
0
].
name
)
Sequelize
.
Helper
.
log
(
"The object should now also contain the data: "
+
person
.
fetchedAssociations
.
pets
[
0
].
name
)
Sequelize
.
Helper
.
log
(
'This
should
do a database request!'
)
Sequelize
.
Helper
.
log
(
'This
won\'t
do a database request!'
)
person
.
getPets
(
function
(
pets
)
{
person
.
getPets
(
function
(
pets
)
{
Sequelize
.
Helper
.
log
(
"Pets: "
+
pets
.
map
(
function
(
pet
)
{
return
pet
.
name
}).
join
(
", "
))
Sequelize
.
Helper
.
log
(
"Pets: "
+
pets
.
map
(
function
(
pet
)
{
return
pet
.
name
}).
join
(
", "
))
Sequelize
.
Helper
.
log
(
"Let's associate with another pet..."
)
Sequelize
.
Helper
.
log
(
"Let's associate with another pet..."
)
person
.
setPets
([
pet1
,
pet2
],
function
()
{
Sequelize
.
Helper
.
log
(
"The set call has stored the pets as associated data!"
)
Sequelize
.
Helper
.
log
(
"And now let's find the pets again! This will make no new database request but serve the already stored pets Bob and Aaron!"
)
Sequelize
.
Helper
.
log
(
'This should do no database request and just serves the already received pets'
)
person
.
getPets
(
function
(
pets
)
{
person
.
getPets
(
function
(
pets
)
{
}
)
Sequelize
.
Helper
.
log
(
"Pets: "
+
pets
.
map
(
function
(
pet
)
{
return
pet
.
name
}).
join
(
", "
)
)
}
)
Sequelize
.
Helper
.
log
(
"Now let's force the reloading of pets!"
)
person
.
getPets
({
refetchAssociations
:
true
},
function
(
pets
)
{
Person
.
find
(
person
.
id
,
{
fetchAssociations
:
true
},
function
(
p
)
{
Sequelize
.
Helper
.
log
(
"Pets: "
+
pets
.
map
(
function
(
pet
)
{
return
pet
.
name
}).
join
(
", "
))
Sequelize
.
Helper
.
log
(
'Works with find as well: '
+
p
.
fetchedAssociations
.
pets
[
0
].
name
)
})
Person
.
findAll
({
fetchAssociations
:
true
},
function
(
people
)
{
Person
.
find
(
person
.
id
,
{
fetchAssociations
:
true
},
function
(
p
)
{
Sequelize
.
Helper
.
log
(
'And also with findAll:'
+
people
[
0
].
fetchedAssociations
.
pets
[
0
].
name
)
var
petNames
=
p
.
fetchedAssociations
.
pets
.
map
(
function
(
pet
)
{
return
pet
.
name
}).
join
(
", "
)
})
Sequelize
.
Helper
.
log
(
'Works with find as well: '
+
petNames
)
})
Person
.
findAll
({
fetchAssociations
:
true
},
function
(
people
)
{
var
petNames
=
people
[
0
].
fetchedAssociations
.
pets
.
map
(
function
(
pet
)
{
return
pet
.
name
}).
join
(
", "
)
Sequelize
.
Helper
.
log
(
'And also with findAll: '
+
petNames
)
})
})
})
})
})
})
})
})
})
})
})
...
...
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