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 a46121ce
authored
Nov 22, 2013
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor a few things to support associations still ;)
1 parent
79c364db
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
35 deletions
lib/associations/belongs-to.js
lib/associations/has-many.js
lib/associations/has-one.js
lib/dao-factory.js
test/dao-factory.test.js
lib/associations/belongs-to.js
View file @
a46121c
...
@@ -32,8 +32,8 @@ module.exports = (function() {
...
@@ -32,8 +32,8 @@ module.exports = (function() {
Helpers
.
addForeignKeyConstraints
(
newAttributes
[
this
.
identifier
],
this
.
target
,
this
.
source
,
this
.
options
)
Helpers
.
addForeignKeyConstraints
(
newAttributes
[
this
.
identifier
],
this
.
target
,
this
.
source
,
this
.
options
)
Utils
.
_
.
defaults
(
this
.
source
.
rawAttributes
,
newAttributes
)
Utils
.
_
.
defaults
(
this
.
source
.
rawAttributes
,
newAttributes
)
// Sync attributes
to DAO proto each time a new assoc is added
// Sync attributes
and setters/getters to DAO prototype
this
.
source
.
DAO
.
prototype
.
attributes
=
Object
.
keys
(
this
.
source
.
DAO
.
prototype
.
rawAttributes
)
this
.
source
.
refreshAttributes
(
)
return
this
return
this
}
}
...
...
lib/associations/has-many.js
View file @
a46121c
...
@@ -109,9 +109,9 @@ module.exports = (function() {
...
@@ -109,9 +109,9 @@ module.exports = (function() {
Utils
.
_
.
defaults
(
this
.
target
.
rawAttributes
,
newAttributes
)
Utils
.
_
.
defaults
(
this
.
target
.
rawAttributes
,
newAttributes
)
}
}
// Sync attributes
to DAO proto each time a new assoc is added
// Sync attributes
and setters/getters to DAO prototype
this
.
target
.
DAO
.
prototype
.
attributes
=
Object
.
keys
(
this
.
target
.
DAO
.
prototype
.
rawAttributes
);
this
.
target
.
refreshAttributes
()
this
.
source
.
DAO
.
prototype
.
attributes
=
Object
.
keys
(
this
.
source
.
DAO
.
prototype
.
rawAttributes
);
this
.
source
.
refreshAttributes
()
return
this
return
this
}
}
...
...
lib/associations/has-one.js
View file @
a46121c
...
@@ -37,9 +37,8 @@ module.exports = (function() {
...
@@ -37,9 +37,8 @@ module.exports = (function() {
Helpers
.
addForeignKeyConstraints
(
newAttributes
[
this
.
identifier
],
this
.
source
,
this
.
target
,
this
.
options
)
Helpers
.
addForeignKeyConstraints
(
newAttributes
[
this
.
identifier
],
this
.
source
,
this
.
target
,
this
.
options
)
Utils
.
_
.
defaults
(
this
.
target
.
rawAttributes
,
newAttributes
)
Utils
.
_
.
defaults
(
this
.
target
.
rawAttributes
,
newAttributes
)
// Sync attributes to DAO proto each time a new assoc is added
// Sync attributes and setters/getters to DAO prototype
this
.
target
.
DAO
.
prototype
.
attributes
=
Object
.
keys
(
this
.
target
.
DAO
.
prototype
.
rawAttributes
);
this
.
target
.
refreshAttributes
()
return
this
return
this
}
}
...
...
lib/dao-factory.js
View file @
a46121c
...
@@ -141,7 +141,35 @@ module.exports = (function() {
...
@@ -141,7 +141,35 @@ module.exports = (function() {
})
})
}
}
var
attributeManipulation
=
{};
this
.
refreshAttributes
();
this
.
DAO
.
prototype
.
booleanValues
=
[]
this
.
DAO
.
prototype
.
defaultValues
=
{}
this
.
DAO
.
prototype
.
validators
=
{}
Utils
.
_
.
each
(
this
.
rawAttributes
,
function
(
definition
,
name
)
{
if
(((
definition
===
DataTypes
.
BOOLEAN
)
||
(
definition
.
type
===
DataTypes
.
BOOLEAN
)))
{
self
.
DAO
.
prototype
.
booleanValues
.
push
(
name
);
}
if
(
definition
.
hasOwnProperty
(
'defaultValue'
))
{
self
.
DAO
.
prototype
.
defaultValues
[
name
]
=
Utils
.
_
.
partial
(
Utils
.
toDefaultValue
,
definition
.
defaultValue
)
}
if
(
definition
.
hasOwnProperty
(
'validate'
))
{
self
.
DAO
.
prototype
.
validators
[
name
]
=
definition
.
validate
;
}
})
this
.
DAO
.
prototype
.
__factory
=
this
this
.
DAO
.
prototype
.
hasDefaultValues
=
!
Utils
.
_
.
isEmpty
(
this
.
DAO
.
prototype
.
defaultValues
)
return
this
}
DAOFactory
.
prototype
.
refreshAttributes
=
function
()
{
var
self
=
this
,
attributeManipulation
=
{};
Utils
.
_
.
each
([
'get'
,
'set'
],
function
(
type
)
{
Utils
.
_
.
each
([
'get'
,
'set'
],
function
(
type
)
{
var
opt
=
type
+
'terMethods'
var
opt
=
type
+
'terMethods'
...
@@ -173,36 +201,17 @@ module.exports = (function() {
...
@@ -173,36 +201,17 @@ module.exports = (function() {
})
})
Utils
.
_
.
each
(
funcs
,
function
(
fct
,
name
)
{
Utils
.
_
.
each
(
funcs
,
function
(
fct
,
name
)
{
if
(
!
attributeManipulation
[
name
])
attributeManipulation
[
name
]
=
{}
if
(
!
attributeManipulation
[
name
])
{
attributeManipulation
[
name
]
=
{
configurable
:
true
}
}
attributeManipulation
[
name
][
type
]
=
fct
attributeManipulation
[
name
][
type
]
=
fct
})
})
})
})
Object
.
defineProperties
(
this
.
DAO
.
prototype
,
attributeManipulation
)
Object
.
defineProperties
(
this
.
DAO
.
prototype
,
attributeManipulation
)
this
.
DAO
.
prototype
.
attributes
=
Object
.
keys
(
this
.
DAO
.
prototype
.
rawAttributes
)
this
.
DAO
.
prototype
.
attributes
=
Object
.
keys
(
this
.
DAO
.
prototype
.
rawAttributes
);
this
.
DAO
.
prototype
.
booleanValues
=
[]
this
.
DAO
.
prototype
.
defaultValues
=
{}
this
.
DAO
.
prototype
.
validators
=
{}
Utils
.
_
.
each
(
this
.
rawAttributes
,
function
(
definition
,
name
)
{
if
(((
definition
===
DataTypes
.
BOOLEAN
)
||
(
definition
.
type
===
DataTypes
.
BOOLEAN
)))
{
self
.
DAO
.
prototype
.
booleanValues
.
push
(
name
);
}
if
(
definition
.
hasOwnProperty
(
'defaultValue'
))
{
self
.
DAO
.
prototype
.
defaultValues
[
name
]
=
Utils
.
_
.
partial
(
Utils
.
toDefaultValue
,
definition
.
defaultValue
)
}
if
(
definition
.
hasOwnProperty
(
'validate'
))
{
self
.
DAO
.
prototype
.
validators
[
name
]
=
definition
.
validate
;
}
})
this
.
DAO
.
prototype
.
__factory
=
this
this
.
DAO
.
prototype
.
hasDefaultValues
=
!
Utils
.
_
.
isEmpty
(
this
.
DAO
.
prototype
.
defaultValues
)
return
this
}
}
DAOFactory
.
prototype
.
sync
=
function
(
options
)
{
DAOFactory
.
prototype
.
sync
=
function
(
options
)
{
...
...
test/dao-factory.test.js
View file @
a46121c
...
@@ -1953,7 +1953,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -1953,7 +1953,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
this
.
User
.
find
({
limit
:
10
}).
success
(
function
(
user
)
{
this
.
User
.
find
({
limit
:
10
}).
success
(
function
(
user
)
{
// it returns an object instead of an array
// it returns an object instead of an array
expect
(
Array
.
isArray
(
user
)).
to
.
not
.
be
.
ok
expect
(
Array
.
isArray
(
user
)).
to
.
not
.
be
.
ok
expect
(
user
.
hasOwnProperty
(
'username'
)).
to
.
be
.
ok
expect
(
user
.
dataValues
.
hasOwnProperty
(
'username'
)).
to
.
be
.
ok
done
()
done
()
})
})
})
})
...
...
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