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 c77c2bc3
authored
Nov 13, 2012
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
associations
1 parent
f5393a25
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
6 deletions
lib/associations/has-one.js
lib/associations/mixin.js
lib/dao-factory.js
lib/associations/has-one.js
View file @
c77c2bc
...
...
@@ -38,7 +38,7 @@ module.exports = (function() {
var
self
=
this
obj
[
this
.
accessors
.
get
]
=
function
()
{
var
id
=
obj
.
id
var
id
=
this
.
id
,
where
=
{}
where
[
self
.
identifier
]
=
id
...
...
lib/associations/mixin.js
View file @
c77c2bc
...
...
@@ -10,6 +10,11 @@ Mixin.hasOne = function(associatedDAO, options) {
// the id is in the foreign table
var
association
=
new
HasOne
(
this
,
associatedDAO
,
Utils
.
_
.
extend
((
options
||
{}),
this
.
options
))
this
.
associations
[
association
.
associationAccessor
]
=
association
.
injectAttributes
()
if
(
this
.
DAO
)
{
association
.
injectGetter
(
this
.
DAO
.
prototype
);
association
.
injectSetter
(
this
.
DAO
.
prototype
);
}
return
this
}
...
...
@@ -17,6 +22,10 @@ Mixin.belongsTo = function(associatedDAO, options) {
// the id is in this table
var
association
=
new
BelongsTo
(
this
,
associatedDAO
,
Utils
.
_
.
extend
((
options
||
{}),
this
.
options
))
this
.
associations
[
association
.
associationAccessor
]
=
association
.
injectAttributes
()
if
(
this
.
DAO
)
{
association
.
injectGetter
(
this
.
DAO
.
prototype
);
association
.
injectSetter
(
this
.
DAO
.
prototype
);
}
return
this
}
...
...
@@ -24,6 +33,11 @@ Mixin.hasMany = function(associatedDAO, options) {
// the id is in the foreign table or in a connecting table
var
association
=
new
HasMany
(
this
,
associatedDAO
,
Utils
.
_
.
extend
((
options
||
{}),
this
.
options
))
this
.
associations
[
association
.
associationAccessor
]
=
association
.
injectAttributes
()
if
(
this
.
DAO
)
{
association
.
injectGetter
(
this
.
DAO
.
prototype
);
association
.
injectSetter
(
this
.
DAO
.
prototype
);
}
return
this
}
...
...
lib/dao-factory.js
View file @
c77c2bc
var
Utils
=
require
(
"./utils"
)
,
DAO
=
require
(
"./dao"
)
,
DataTypes
=
require
(
"./data-types"
)
,
Util
=
require
(
'util'
)
module
.
exports
=
(
function
()
{
var
DAOFactory
=
function
(
name
,
attributes
,
options
)
{
...
...
@@ -25,6 +26,15 @@ module.exports = (function() {
// extract validation
this
.
validate
=
this
.
options
.
validate
||
{}
// DAO prototype
this
.
DAO
=
function
(
values
,
options
)
{
DAO
.
apply
(
this
,
arguments
);
};
Util
.
inherits
(
this
.
DAO
,
DAO
);
}
Object
.
defineProperty
(
DAOFactory
.
prototype
,
'attributes'
,
{
...
...
@@ -188,7 +198,7 @@ module.exports = (function() {
}
DAOFactory
.
prototype
.
build
=
function
(
values
,
options
)
{
var
instance
=
new
DAO
(
values
,
Utils
.
_
.
extend
(
this
.
options
,
{
hasPrimaryKeys
:
this
.
hasPrimaryKeys
,
factory
:
this
}))
var
instance
=
new
this
.
DAO
(
values
,
Utils
.
_
.
extend
(
this
.
options
,
{
hasPrimaryKeys
:
this
.
hasPrimaryKeys
,
factory
:
this
}))
,
self
=
this
options
=
options
||
{}
...
...
@@ -219,10 +229,10 @@ module.exports = (function() {
})
Utils
.
_
.
each
(
this
.
options
.
instanceMethods
||
{},
function
(
fct
,
name
)
{
instance
[
name
]
=
fct
})
Utils
.
_
.
each
(
this
.
associations
,
function
(
association
)
{
association
.
injectGetter
(
instance
)
association
.
injectSetter
(
instance
)
})
//
Utils._.each(this.associations, function(association) {
//
association.injectGetter(instance)
//
association.injectSetter(instance)
//
})
instance
.
isNewRecord
=
options
.
hasOwnProperty
(
'isNewRecord'
)
?
options
.
isNewRecord
:
true
instance
.
selectedValues
=
values
...
...
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