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 19828b24
authored
Oct 14, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/chill117/sequelize
into chill117-master
2 parents
5f882ec7
6445ee27
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
1 deletions
lib/dao-factory.js
test/dao-factory.test.js
lib/dao-factory.js
View file @
19828b2
...
...
@@ -1075,7 +1075,10 @@ module.exports = (function() {
if
(
include
.
hasOwnProperty
(
'attributes'
))
{
var
primaryKeys
;
if
(
include
.
daoFactory
.
hasPrimaryKeys
)
{
primaryKeys
=
include
.
daoFactory
.
primaryKeys
primaryKeys
=
[]
for
(
var
field_name
in
include
.
daoFactory
.
primaryKeys
)
{
primaryKeys
.
push
(
field_name
)
}
}
else
{
primaryKeys
=
[
'id'
]
}
...
...
test/dao-factory.test.js
View file @
19828b2
...
...
@@ -2056,6 +2056,61 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it
(
'getting parent data in many to one relationship'
,
function
(
done
)
{
var
self
=
this
;
var
User
=
self
.
sequelize
.
define
(
'User'
,
{
id
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
},
username
:
{
type
:
Sequelize
.
STRING
}
})
var
Message
=
self
.
sequelize
.
define
(
'Message'
,
{
id
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
},
user_id
:
{
type
:
Sequelize
.
INTEGER
},
message
:
{
type
:
Sequelize
.
STRING
}
})
User
.
hasMany
(
Message
)
Message
.
belongsTo
(
User
,
{
foreignKey
:
'user_id'
})
Message
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'test_testerson'
}).
success
(
function
(
user
)
{
Message
.
create
({
user_id
:
user
.
id
,
message
:
'hi there!'
}).
success
(
function
(
message
)
{
Message
.
create
({
user_id
:
user
.
id
,
message
:
'a second message'
}).
success
(
function
(
message
)
{
Message
.
findAll
({
where
:
{
user_id
:
user
.
id
},
attributes
:
[
'user_id'
,
'message'
],
include
:
[{
model
:
User
,
as
:
User
.
tableName
,
attributes
:
[
'username'
]
}]
}).
success
(
function
(
messages
)
{
expect
(
messages
.
length
).
to
.
equal
(
2
);
expect
(
messages
[
0
].
message
).
to
.
equal
(
'hi there!'
);
expect
(
messages
[
0
].
user
.
username
).
to
.
equal
(
'test_testerson'
);
expect
(
messages
[
1
].
message
).
to
.
equal
(
'a second message'
);
expect
(
messages
[
1
].
user
.
username
).
to
.
equal
(
'test_testerson'
);
done
()
})
})
})
})
})
})
})
it
(
'allows mulitple assocations of the same model with different alias'
,
function
(
done
)
{
var
self
=
this
...
...
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