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 7aebe2c6
authored
May 09, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed example
1 parent
8347de69
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
27 deletions
examples/Associations/app.js
examples/Associations/app.js
View file @
7aebe2c
...
@@ -8,34 +8,52 @@
...
@@ -8,34 +8,52 @@
The rest of the example is about setting and getting the associated data.
The rest of the example is about setting and getting the associated data.
*/
*/
var
Sequelize
=
require
(
__dirname
+
"/../../lib/sequelize/Sequelize"
).
Sequelize
,
var
Sequelize
=
require
(
__dirname
+
"/../../index"
)
sequelize
=
new
Sequelize
(
"sequelize_test"
,
"root"
,
null
,
{
disableLogging
:
true
}),
,
config
=
require
(
__dirname
+
"/../../test/config"
)
Person
=
sequelize
.
define
(
'person'
,
{
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
name
:
Sequelize
.
STRING
,
Person
=
sequelize
.
define
(
'Person'
,
{
name
:
Sequelize
.
STRING
})
}),
,
Pet
=
sequelize
.
define
(
'Pet'
,
{
name
:
Sequelize
.
STRING
})
Pet
=
sequelize
.
define
(
'pet'
,
{
name
:
Sequelize
.
STRING
})
Person
.
hasMany
(
'brothers'
)
Person
.
hasMany
(
Person
,
{
as
:
'Brothers'
}
)
Person
.
hasMany
(
'sisters'
)
Person
.
hasMany
(
Person
,
{
as
:
'Sisters'
}
)
Person
.
hasOne
AndBelongsTo
(
'father'
,
Person
)
Person
.
hasOne
(
Person
,
{
as
:
'Father'
,
foreignKey
:
'FatherId'
}
)
Person
.
hasOne
AndBelongsTo
(
'mother'
,
Person
)
Person
.
hasOne
(
Person
,
{
as
:
'Mother'
,
foreignKey
:
'MotherId'
}
)
Person
.
hasMany
AndBelongsTo
(
'pets'
,
Pet
,
'owner'
)
Person
.
hasMany
(
Pet
)
Sequelize
.
chainQueries
([{
drop
:
sequelize
},
{
sync
:
sequelize
}],
function
()
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
var
person
=
new
Person
({
name
:
'Luke'
}),
,
person
=
Person
.
build
({
name
:
'Luke'
})
mother
=
new
Person
({
name
:
'Jane'
}),
,
mother
=
Person
.
build
({
name
:
'Jane'
})
father
=
new
Person
({
name
:
'John'
}),
,
father
=
Person
.
build
({
name
:
'John'
})
brother
=
new
Person
({
name
:
'Brother'
}),
,
brother
=
Person
.
build
({
name
:
'Brother'
})
sister
=
new
Person
({
name
:
'Sister'
}),
,
sister
=
Person
.
build
({
name
:
'Sister'
})
pet
=
new
Pet
({
name
:
'Bob'
})
,
pet
=
Pet
.
build
({
name
:
'Bob'
})
Sequelize
.
chainQueries
({
save
:
[
person
,
mother
,
father
,
brother
,
sister
,
pet
]},
function
()
{
sequelize
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
person
.
setMother
(
mother
,
function
(
mom
)
{
Sequelize
.
Helper
.
log
(
'my mom: '
+
mom
.
name
)
})
chainer
person
.
setFather
(
father
,
function
(
dad
)
{
Sequelize
.
Helper
.
log
(
'my dad: '
+
dad
.
name
)
})
.
add
(
person
.
save
())
person
.
setBrothers
([
brother
],
function
(
bros
)
{
Sequelize
.
Helper
.
log
(
"ma bro: "
+
bros
[
0
].
name
)})
.
add
(
mother
.
save
())
person
.
setSisters
([
sister
],
function
(
sis
)
{
Sequelize
.
Helper
.
log
(
"ma sis: "
+
sis
[
0
].
name
)})
.
add
(
father
.
save
())
person
.
setPets
([
pet
],
function
(
pets
)
{
Sequelize
.
Helper
.
log
(
'my pet: '
+
pets
[
0
].
name
)})
.
add
(
brother
.
save
())
.
add
(
sister
.
save
())
.
add
(
pet
.
save
())
chainer
.
run
().
on
(
'success'
,
function
()
{
person
.
setMother
(
mother
).
on
(
'success'
,
function
()
{
person
.
getMother
().
on
(
'success'
,
function
(
mom
)
{
console
.
log
(
'my mom: '
,
mom
.
name
)
})})
person
.
setFather
(
father
).
on
(
'success'
,
function
()
{
person
.
getFather
().
on
(
'success'
,
function
(
dad
)
{
console
.
log
(
'my dad: '
,
dad
.
name
)
})})
person
.
setBrothers
([
brother
]).
on
(
'success'
,
function
()
{
person
.
getBrothers
().
on
(
'success'
,
function
(
brothers
)
{
console
.
log
(
"my brothers: "
+
brothers
.
map
(
function
(
b
)
{
return
b
.
name
}))
})})
person
.
setSisters
([
sister
]).
on
(
'success'
,
function
()
{
person
.
getSisters
().
on
(
'success'
,
function
(
sisters
)
{
console
.
log
(
"my sisters: "
+
sisters
.
map
(
function
(
s
)
{
return
s
.
name
}))
})})
person
.
setPets
([
pet
]).
on
(
'success'
,
function
()
{
person
.
getPets
().
on
(
'success'
,
function
(
pets
)
{
console
.
log
(
"my pets: "
+
pets
.
map
(
function
(
p
)
{
return
p
.
name
}))
})})
}).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
})
})
\ No newline at end of file
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