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 c13ff3de
authored
Sep 12, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added wrapper for hasOne + belongsTo and hasMany + belongsTo
1 parent
1cf78a47
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
8 deletions
examples/Associations/app.js
lib/sequelize/SequelizeTable.js
examples/Associations/app.js
View file @
c13ff3d
...
...
@@ -11,14 +11,9 @@ var Pet = sequelize.define('pet', {
Person
.
hasMany
(
'brothers'
)
Person
.
hasMany
(
'sisters'
)
var
fatherAssoc
=
Person
.
hasOne
(
'father'
,
Person
)
var
motherAssoc
=
Person
.
hasOne
(
'mother'
,
Person
)
Person
.
belongsTo
(
'father'
,
Person
,
fatherAssoc
)
Person
.
belongsTo
(
'mother'
,
Person
,
motherAssoc
)
var
petAssoc
=
Person
.
hasMany
(
'pets'
,
Pet
)
Pet
.
belongsTo
(
'owner'
,
Person
,
petAssoc
)
Person
.
hasOneAndBelongsTo
(
'father'
,
Person
)
Person
.
hasOneAndBelongsTo
(
'mother'
,
Person
)
Person
.
hasManyAndBelongsTo
(
'pets'
,
Pet
,
'owner'
)
Sequelize
.
chainQueries
([{
drop
:
sequelize
},
{
sync
:
sequelize
}],
function
()
{
var
person
=
new
Person
({
name
:
'Luke'
}),
...
...
lib/sequelize/SequelizeTable.js
View file @
c13ff3d
...
...
@@ -178,6 +178,11 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
}
},
hasManyAndBelongsTo
:
function
(
assocName
,
_table
,
backAssocName
)
{
var
assoc
=
table
.
hasMany
(
assocName
,
_table
)
_table
.
belongsTo
(
backAssocName
||
assocName
,
table
,
assoc
)
},
hasOne
:
function
(
assocName
,
_table
)
{
var
Factory
=
new
require
(
"./Factory"
).
Factory
(
Sequelize
,
sequelize
),
association
=
{
name
:
assocName
,
table
:
_table
,
type
:
'hasOne'
}
...
...
@@ -188,6 +193,11 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
return
association
},
hasOneAndBelongsTo
:
function
(
assocName
,
_table
,
backAssocName
)
{
var
assoc
=
table
.
hasOne
(
assocName
,
_table
)
_table
.
belongsTo
(
backAssocName
||
assocName
,
table
,
assoc
)
},
belongsTo
:
function
(
assocName
,
_table
,
backAssociation
)
{
if
(
typeof
backAssociation
==
'undefined'
)
throw
new
Error
(
"Calling belongsTo with only two parameters is deprecated! Please take a look at the example in the repository!"
)
...
...
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