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 c8235a54
authored
May 10, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(include): make it possible to filter attributes on the through table
1 parent
23f0460a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
11 deletions
lib/instance.js
lib/model.js
test/include/findAll.test.js
lib/instance.js
View file @
c8235a5
...
@@ -375,15 +375,16 @@ module.exports = (function() {
...
@@ -375,15 +375,16 @@ module.exports = (function() {
attributes
:
include
.
originalAttributes
attributes
:
include
.
originalAttributes
}
}
}
}
if
(
include
.
originalAttributes
===
undefined
||
include
.
originalAttributes
.
length
)
{
// downcase the first char
accessor
=
accessor
.
slice
(
0
,
1
).
toLowerCase
()
+
accessor
.
slice
(
1
)
// downcase the first char
if
(
association
.
isSingleAssociation
)
{
accessor
=
accessor
.
slice
(
0
,
1
).
toLowerCase
()
+
accessor
.
slice
(
1
)
accessor
=
Utils
.
singularize
(
accessor
,
self
.
Model
.
options
.
language
)
self
[
accessor
]
=
self
.
dataValues
[
accessor
]
=
isEmpty
?
null
:
include
.
model
.
build
(
value
[
0
],
childOptions
)
if
(
association
.
isSingleAssociation
)
{
}
else
{
accessor
=
Utils
.
singularize
(
accessor
,
self
.
Model
.
options
.
language
)
self
[
accessor
]
=
self
.
dataValues
[
accessor
]
=
isEmpty
?
[]
:
include
.
model
.
bulkBuild
(
value
,
childOptions
)
self
[
accessor
]
=
self
.
dataValues
[
accessor
]
=
isEmpty
?
null
:
include
.
model
.
build
(
value
[
0
],
childOptions
)
}
}
else
{
self
[
accessor
]
=
self
.
dataValues
[
accessor
]
=
isEmpty
?
[]
:
include
.
model
.
bulkBuild
(
value
,
childOptions
)
}
}
};
};
...
...
lib/model.js
View file @
c8235a5
...
@@ -1774,7 +1774,9 @@ module.exports = (function() {
...
@@ -1774,7 +1774,9 @@ module.exports = (function() {
}
}
// pseudo include just needed the attribute logic, return
// pseudo include just needed the attribute logic, return
if
(
include
.
_pseudo
)
return
include
if
(
include
.
_pseudo
)
{
return
include
}
// check if the current Model is actually associated with the passed Model - or it's a pseudo include
// check if the current Model is actually associated with the passed Model - or it's a pseudo include
var
association
=
this
.
getAssociation
(
include
.
model
,
include
.
as
)
var
association
=
this
.
getAssociation
(
include
.
model
,
include
.
as
)
...
@@ -1787,14 +1789,14 @@ module.exports = (function() {
...
@@ -1787,14 +1789,14 @@ module.exports = (function() {
if
(
!
include
.
include
)
include
.
include
=
[]
if
(
!
include
.
include
)
include
.
include
=
[]
var
through
=
include
.
association
.
through
var
through
=
include
.
association
.
through
include
.
through
=
{
include
.
through
=
Utils
.
_
.
defaults
(
include
.
through
||
{},
{
model
:
through
,
model
:
through
,
as
:
Utils
.
singularize
(
through
.
tableName
,
through
.
options
.
language
),
as
:
Utils
.
singularize
(
through
.
tableName
,
through
.
options
.
language
),
association
:
{
association
:
{
isSingleAssociation
:
true
isSingleAssociation
:
true
},
},
_pseudo
:
true
_pseudo
:
true
}
}
)
include
.
include
.
push
(
include
.
through
)
include
.
include
.
push
(
include
.
through
)
tableNames
[
through
.
tableName
]
=
true
tableNames
[
through
.
tableName
]
=
true
...
...
test/include/findAll.test.js
View file @
c8235a5
...
@@ -1451,6 +1451,28 @@ describe(Support.getTestDialectTeaser("Include"), function () {
...
@@ -1451,6 +1451,28 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
})
})
it
(
'should be possible to turn off the attributes for the through table'
,
function
(
done
)
{
var
self
=
this
this
.
fixtureA
(
function
()
{
self
.
models
.
Product
.
findAll
({
attributes
:
[
'title'
],
include
:
[
{
model
:
self
.
models
.
Tag
,
through
:
{
attributes
:
[]},
required
:
true
}
],
}).
done
(
function
(
err
,
products
)
{
expect
(
err
).
not
.
to
.
be
.
ok
products
.
forEach
(
function
(
product
)
{
expect
(
product
.
tags
.
length
).
to
.
be
.
ok
product
.
tags
.
forEach
(
function
(
tag
)
{
expect
(
tag
.
get
().
productTags
).
not
.
to
.
be
.
ok
})
})
done
()
})
})
});
// Test case by @eshell
// Test case by @eshell
it
(
'should be possible not to include the main id in the attributes'
,
function
(
done
)
{
it
(
'should be possible not to include the main id in the attributes'
,
function
(
done
)
{
var
Member
=
this
.
sequelize
.
define
(
'Member'
,
{
var
Member
=
this
.
sequelize
.
define
(
'Member'
,
{
...
...
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