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 48f39859
authored
May 19, 2015
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add util function to format the references property
1 parent
10029e1f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletions
lib/utils.js
test/integration/utils.test.js
lib/utils.js
View file @
48f3985
...
@@ -255,7 +255,6 @@ var Utils = module.exports = {
...
@@ -255,7 +255,6 @@ var Utils = module.exports = {
return
true
;
return
true
;
},
},
removeNullValuesFromHash
:
function
(
hash
,
omitNull
,
options
)
{
removeNullValuesFromHash
:
function
(
hash
,
omitNull
,
options
)
{
var
result
=
hash
;
var
result
=
hash
;
...
@@ -392,6 +391,27 @@ var Utils = module.exports = {
...
@@ -392,6 +391,27 @@ var Utils = module.exports = {
validateParameter
:
function
(
value
,
expectation
,
options
)
{
validateParameter
:
function
(
value
,
expectation
,
options
)
{
return
ParameterValidator
.
check
(
value
,
expectation
,
options
);
return
ParameterValidator
.
check
(
value
,
expectation
,
options
);
},
formatReferences
:
function
(
obj
)
{
var
references
=
{};
if
(
!
obj
||
!
_
.
isPlainObject
(
obj
)
||
!
obj
.
references
)
{
return
obj
;
}
if
(
_
.
isPlainObject
(
obj
.
references
))
{
references
=
obj
.
references
;
}
else
{
references
.
model
=
obj
.
references
;
}
if
(
obj
.
referencesKey
)
{
references
.
key
=
obj
.
referencesKey
;
delete
obj
.
referencesKey
;
}
return
_
.
extend
(
obj
,
{
references
:
references
});
}
}
};
};
...
...
test/integration/utils.test.js
View file @
48f3985
...
@@ -189,4 +189,26 @@ describe(Support.getTestDialectTeaser('Utils'), function() {
...
@@ -189,4 +189,26 @@ describe(Support.getTestDialectTeaser('Utils'), function() {
expect
(
Utils
.
singularize
(
'status'
)).
to
.
equal
(
'status'
);
expect
(
Utils
.
singularize
(
'status'
)).
to
.
equal
(
'status'
);
});
});
});
});
describe
(
'formatReferences'
,
function
()
{
([
[
undefined
,
undefined
],
[
false
,
false
],
[
null
,
null
],
[
'a'
,
'a'
],
[{},
{}],
[{
a
:
1
},
{
a
:
1
}],
[{
referencesKey
:
1
},
{
referencesKey
:
1
}],
[{
references
:
'a'
},
{
references
:
{
model
:
'a'
}}],
[{
references
:
'a'
,
referencesKey
:
1
},
{
references
:
{
model
:
'a'
,
key
:
1
}}],
[{
references
:
{
model
:
1
}},
{
references
:
{
model
:
1
}}]
]).
forEach
(
function
(
test
)
{
var
input
=
test
[
0
];
var
output
=
test
[
1
];
it
(
'converts '
+
JSON
.
stringify
(
input
)
+
' to '
+
JSON
.
stringify
(
output
),
function
()
{
expect
(
Utils
.
formatReferences
(
input
)).
to
.
deep
.
equal
(
output
);
});
});
});
});
});
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