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 6b7e3e0a
authored
Sep 07, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add field mapping support for and()/or(), fixes #2237
1 parent
7aa4c0ea
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
13 deletions
lib/model.js
test/model/attributes.test.js
lib/model.js
View file @
6b7e3e0
...
@@ -1575,10 +1575,24 @@ module.exports = (function() {
...
@@ -1575,10 +1575,24 @@ module.exports = (function() {
}
}
if
(
options
.
where
)
{
if
(
options
.
where
)
{
for
(
var
attr
in
options
.
where
)
{
var
attributes
=
options
.
where
if
(
Model
.
rawAttributes
[
attr
]
&&
Model
.
rawAttributes
[
attr
].
field
)
{
,
attribute
;
options
.
where
[
Model
.
rawAttributes
[
attr
].
field
]
=
options
.
where
[
attr
];
delete
options
.
where
[
attr
];
if
(
options
.
where
instanceof
Utils
.
and
||
options
.
where
instanceof
Utils
.
or
)
{
attributes
=
undefined
;
options
.
where
.
args
=
options
.
where
.
args
.
map
(
function
(
where
)
{
return
mapFieldNames
({
where
:
where
},
Model
).
where
;
});
}
if
(
attributes
)
{
for
(
attribute
in
attributes
)
{
if
(
Model
.
rawAttributes
[
attribute
]
&&
Model
.
rawAttributes
[
attribute
].
field
)
{
attributes
[
Model
.
rawAttributes
[
attribute
].
field
]
=
attributes
[
attribute
];
delete
attributes
[
attribute
];
}
}
}
}
}
}
}
...
...
test/model/attributes.test.js
View file @
6b7e3e0
...
@@ -66,10 +66,10 @@ describe(Support.getTestDialectTeaser("Model"), function () {
...
@@ -66,10 +66,10 @@ describe(Support.getTestDialectTeaser("Model"), function () {
type
:
DataTypes
.
STRING
,
type
:
DataTypes
.
STRING
,
field
:
'comment_text'
field
:
'comment_text'
},
},
notes
:
{
notes
:
{
type
:
DataTypes
.
STRING
,
type
:
DataTypes
.
STRING
,
field
:
'notes'
field
:
'notes'
}
}
},
{
},
{
tableName
:
'comments'
,
tableName
:
'comments'
,
timestamps
:
false
timestamps
:
false
...
@@ -127,9 +127,9 @@ describe(Support.getTestDialectTeaser("Model"), function () {
...
@@ -127,9 +127,9 @@ describe(Support.getTestDialectTeaser("Model"), function () {
comment_text
:
{
comment_text
:
{
type
:
DataTypes
.
STRING
type
:
DataTypes
.
STRING
},
},
notes
:
{
notes
:
{
type
:
DataTypes
.
STRING
type
:
DataTypes
.
STRING
}
}
})
})
]);
]);
});
});
...
@@ -240,6 +240,24 @@ describe(Support.getTestDialectTeaser("Model"), function () {
...
@@ -240,6 +240,24 @@ describe(Support.getTestDialectTeaser("Model"), function () {
});
});
});
});
it
(
'should work with a where or'
,
function
()
{
var
self
=
this
;
return
this
.
User
.
create
({
name
:
'Foobar'
}).
then
(
function
()
{
return
self
.
User
.
find
({
where
:
self
.
sequelize
.
or
({
name
:
'Foobar'
},
{
name
:
'Lollerskates'
})
});
}).
then
(
function
(
user
)
{
expect
(
user
).
to
.
be
.
ok
;
});
});
it
(
'should work with bulkCreate and findAll'
,
function
()
{
it
(
'should work with bulkCreate and findAll'
,
function
()
{
var
self
=
this
;
var
self
=
this
;
return
this
.
User
.
bulkCreate
([{
return
this
.
User
.
bulkCreate
([{
...
@@ -318,7 +336,25 @@ describe(Support.getTestDialectTeaser("Model"), function () {
...
@@ -318,7 +336,25 @@ describe(Support.getTestDialectTeaser("Model"), function () {
expect
(
comment
.
get
(
'notes'
)).
to
.
equal
(
'Barfoo'
);
expect
(
comment
.
get
(
'notes'
)).
to
.
equal
(
'Barfoo'
);
});
});
});
});
it
(
'should work with with an belongsTo association getter'
,
function
()
{
var
userId
=
Math
.
floor
(
Math
.
random
()
*
100000
);
return
Promise
.
join
(
this
.
User
.
create
({
id
:
userId
}),
this
.
Task
.
create
({
user_id
:
userId
})
).
spread
(
function
(
user
,
task
)
{
return
[
user
,
task
.
getUser
()];
}).
spread
(
function
(
userA
,
userB
)
{
expect
(
userA
.
get
(
'id'
)).
to
.
equal
(
userB
.
get
(
'id'
));
expect
(
userA
.
get
(
'id'
)).
to
.
equal
(
userId
);
expect
(
userB
.
get
(
'id'
)).
to
.
equal
(
userId
);
});
});
});
});
describe
(
'types'
,
function
()
{
describe
(
'types'
,
function
()
{
...
@@ -469,7 +505,6 @@ describe(Support.getTestDialectTeaser("Model"), function () {
...
@@ -469,7 +505,6 @@ describe(Support.getTestDialectTeaser("Model"), function () {
test_value
:
{
test_value
:
{
type
:
Sequelize
.
INTEGER
,
type
:
Sequelize
.
INTEGER
,
set
:
function
(
v
)
{
set
:
function
(
v
)
{
console
.
log
(
"set called"
);
self
.
callCount
++
;
self
.
callCount
++
;
this
.
setDataValue
(
'test_value'
,
v
+
1
);
this
.
setDataValue
(
'test_value'
,
v
+
1
);
}
}
...
...
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