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 5ab3b62b
authored
Dec 27, 2013
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for build with includes
1 parent
ca6a9e2a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
2 deletions
lib/dao.js
test/dao-factory.test.js
lib/dao.js
View file @
5ab3b62
...
@@ -529,6 +529,8 @@ module.exports = (function() {
...
@@ -529,6 +529,8 @@ module.exports = (function() {
for
(
key
in
attrs
)
{
for
(
key
in
attrs
)
{
if
(
options
.
include
&&
options
.
includeNames
.
indexOf
(
key
)
!==
-
1
)
{
if
(
options
.
include
&&
options
.
includeNames
.
indexOf
(
key
)
!==
-
1
)
{
if
(
!
Array
.
isArray
(
attrs
[
key
]))
attrs
[
key
]
=
[
attrs
[
key
]];
var
include
=
_
.
find
(
options
.
include
,
function
(
include
)
{
var
include
=
_
.
find
(
options
.
include
,
function
(
include
)
{
return
include
.
as
===
key
||
(
include
.
as
.
slice
(
0
,
1
).
toLowerCase
()
+
include
.
as
.
slice
(
1
))
===
key
return
include
.
as
===
key
||
(
include
.
as
.
slice
(
0
,
1
).
toLowerCase
()
+
include
.
as
.
slice
(
1
))
===
key
})
})
...
...
test/dao-factory.test.js
View file @
5ab3b62
...
@@ -369,7 +369,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -369,7 +369,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
done
()
done
()
})
})
/*
describe('include', function () {
describe
(
'include'
,
function
()
{
it
(
'should support basic includes'
,
function
()
{
it
(
'should support basic includes'
,
function
()
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
title
:
Sequelize
.
STRING
title
:
Sequelize
.
STRING
...
@@ -410,7 +410,59 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -410,7 +410,59 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect
(
product
.
user
).
to
.
be
.
ok
expect
(
product
.
user
).
to
.
be
.
ok
expect
(
product
.
user
.
Model
).
to
.
equal
(
User
)
expect
(
product
.
user
.
Model
).
to
.
equal
(
User
)
})
})
})*/
it
(
'should support includes with aliases'
,
function
()
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
title
:
Sequelize
.
STRING
})
var
Tag
=
this
.
sequelize
.
define
(
'Tag'
,
{
name
:
Sequelize
.
STRING
})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
first_name
:
Sequelize
.
STRING
,
last_name
:
Sequelize
.
STRING
})
Product
.
hasMany
(
Tag
,
{
as
:
'Categories'
})
Product
.
hasMany
(
User
,
{
as
:
'Followers'
,
through
:
'product_followers'
})
User
.
hasMany
(
Product
,
{
as
:
'Following'
,
through
:
'product_followers'
})
var
product
=
Product
.
build
({
id
:
1
,
title
:
'Chair'
,
categories
:
[
{
id
:
1
,
name
:
'Alpha'
},
{
id
:
2
,
name
:
'Beta'
},
{
id
:
3
,
name
:
'Charlie'
},
{
id
:
4
,
name
:
'Delta'
}
],
followers
:
[
{
id
:
1
,
first_name
:
'Mick'
,
last_name
:
'Hansen'
},
{
id
:
2
,
first_name
:
'Jan'
,
last_name
:
'Meier'
}
]
},
{
include
:
[
{
model
:
User
,
as
:
'Followers'
},
{
model
:
Tag
,
as
:
'Categories'
}
]
})
expect
(
product
.
categories
).
to
.
be
.
ok
expect
(
product
.
categories
.
length
).
to
.
equal
(
4
)
expect
(
product
.
categories
[
0
].
Model
).
to
.
equal
(
Tag
)
expect
(
product
.
followers
).
to
.
be
.
ok
expect
(
product
.
followers
.
length
).
to
.
equal
(
2
)
expect
(
product
.
followers
[
0
].
Model
).
to
.
equal
(
User
)
})
})
})
})
describe
(
'findOrInitialize'
,
function
()
{
describe
(
'findOrInitialize'
,
function
()
{
...
...
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