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 69e797e6
authored
Sep 08, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(model): add model.removeAttribute(key), closes #1026
1 parent
5c59702a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
1 deletions
lib/instance.js
lib/model.js
test/dao-factory/create.test.js
lib/instance.js
View file @
69e797e
...
@@ -199,7 +199,7 @@ module.exports = (function() {
...
@@ -199,7 +199,7 @@ module.exports = (function() {
for
(
_key
in
this
.
dataValues
)
{
for
(
_key
in
this
.
dataValues
)
{
if
(
!
values
.
hasOwnProperty
(
_key
)
&&
this
.
dataValues
.
hasOwnProperty
(
_key
))
{
if
(
!
values
.
hasOwnProperty
(
_key
)
&&
this
.
dataValues
.
hasOwnProperty
(
_key
))
{
if
(
options
.
plain
&&
this
.
options
.
include
&&
this
.
options
.
includeNames
.
indexOf
(
_key
)
!==
-
1
)
{
if
(
options
&&
options
.
plain
&&
this
.
options
.
include
&&
this
.
options
.
includeNames
.
indexOf
(
_key
)
!==
-
1
)
{
values
[
_key
]
=
this
.
dataValues
[
_key
].
get
({
plain
:
options
.
plain
});
values
[
_key
]
=
this
.
dataValues
[
_key
].
get
({
plain
:
options
.
plain
});
}
else
{
}
else
{
values
[
_key
]
=
this
.
dataValues
[
_key
];
values
[
_key
]
=
this
.
dataValues
[
_key
];
...
...
lib/model.js
View file @
69e797e
...
@@ -378,6 +378,15 @@ module.exports = (function() {
...
@@ -378,6 +378,15 @@ module.exports = (function() {
};
};
/**
/**
* Remove attribute from model definition
* @param {String} [attribute]
*/
Model
.
prototype
.
removeAttribute
=
function
(
attribute
)
{
delete
this
.
rawAttributes
[
attribute
];
this
.
refreshAttributes
();
};
/**
* Sync this Model to the DB, that is create the table. Upon success, the callback will be called with the model instance (this)
* Sync this Model to the DB, that is create the table. Upon success, the callback will be called with the model instance (this)
* @see {Sequelize#sync} for options
* @see {Sequelize#sync} for options
* @return {Promise<this>}
* @return {Promise<this>}
...
...
test/dao-factory/create.test.js
View file @
69e797e
...
@@ -252,6 +252,30 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -252,6 +252,30 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
'works without any primary key'
,
function
()
{
var
Log
=
this
.
sequelize
.
define
(
'log'
,
{
level
:
DataTypes
.
STRING
});
Log
.
removeAttribute
(
'id'
);
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Promise
.
join
(
Log
.
create
({
level
:
'info'
}),
Log
.
bulkCreate
([
{
level
:
'error'
},
{
level
:
'debug'
}
])
);
}).
then
(
function
()
{
return
Log
.
findAll
();
}).
then
(
function
(
logs
)
{
logs
.
forEach
(
function
(
log
)
{
expect
(
log
.
get
(
'id'
)).
not
.
to
.
be
.
ok
;
});
});
});
it
(
'supports transactions'
,
function
(
done
)
{
it
(
'supports transactions'
,
function
(
done
)
{
var
self
=
this
;
var
self
=
this
;
this
.
sequelize
.
transaction
().
then
(
function
(
t
)
{
this
.
sequelize
.
transaction
().
then
(
function
(
t
)
{
...
...
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