mirror of https://gitee.com/bigwinds/arangodb
Foxx Repository: Save, Replace, ReplaceById return the model
For convenience, this is quite useful in some cases
This commit is contained in:
parent
fba6c94671
commit
43988bb3ae
|
@ -123,7 +123,7 @@ function RepositoryMethodsSpec() {
|
||||||
.withArguments(modelData)
|
.withArguments(modelData)
|
||||||
.andReturn(id_and_rev);
|
.andReturn(id_and_rev);
|
||||||
|
|
||||||
instance.save(model);
|
assertEqual(instance.save(model), model);
|
||||||
|
|
||||||
model.assertIsSatisfied();
|
model.assertIsSatisfied();
|
||||||
collection.assertIsSatisfied();
|
collection.assertIsSatisfied();
|
||||||
|
@ -167,7 +167,7 @@ function RepositoryMethodsSpec() {
|
||||||
.withArguments(id, data)
|
.withArguments(id, data)
|
||||||
.andReturn(id_and_rev);
|
.andReturn(id_and_rev);
|
||||||
|
|
||||||
instance.replace(model);
|
assertEqual(instance.replace(model), model);
|
||||||
|
|
||||||
collection.assertIsSatisfied();
|
collection.assertIsSatisfied();
|
||||||
model.assertIsSatisfied();
|
model.assertIsSatisfied();
|
||||||
|
@ -187,7 +187,7 @@ function RepositoryMethodsSpec() {
|
||||||
.withArguments(id, data)
|
.withArguments(id, data)
|
||||||
.andReturn(id_and_rev);
|
.andReturn(id_and_rev);
|
||||||
|
|
||||||
instance.replaceById(id, model);
|
assertEqual(instance.replaceById(id, model), model);
|
||||||
|
|
||||||
collection.assertIsSatisfied();
|
collection.assertIsSatisfied();
|
||||||
model.assertIsSatisfied();
|
model.assertIsSatisfied();
|
||||||
|
|
|
@ -105,11 +105,13 @@ _.extend(Repository.prototype, {
|
||||||
/// @brief Save a model into the database
|
/// @brief Save a model into the database
|
||||||
///
|
///
|
||||||
/// Expects a model. Will set the ID and Rev on the model.
|
/// Expects a model. Will set the ID and Rev on the model.
|
||||||
|
/// Returns the model (for convenience).
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
save: function (model) {
|
save: function (model) {
|
||||||
'use strict';
|
'use strict';
|
||||||
var id_and_rev = this.collection.save(model.forDB());
|
var id_and_rev = this.collection.save(model.forDB());
|
||||||
model.set(id_and_rev);
|
model.set(id_and_rev);
|
||||||
|
return model;
|
||||||
},
|
},
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -140,6 +142,7 @@ _.extend(Repository.prototype, {
|
||||||
///
|
///
|
||||||
/// Find the model in the database by its `_id` and replace it with this version.
|
/// Find the model in the database by its `_id` and replace it with this version.
|
||||||
/// Expects a model. Sets the Revision of the model.
|
/// Expects a model. Sets the Revision of the model.
|
||||||
|
/// Returns the model (for convenience).
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
replace: function (model) {
|
replace: function (model) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
@ -147,6 +150,7 @@ _.extend(Repository.prototype, {
|
||||||
data = model.forDB(),
|
data = model.forDB(),
|
||||||
id_and_rev = this.collection.replace(id, data);
|
id_and_rev = this.collection.replace(id, data);
|
||||||
model.set(id_and_rev);
|
model.set(id_and_rev);
|
||||||
|
return model;
|
||||||
},
|
},
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -156,12 +160,14 @@ _.extend(Repository.prototype, {
|
||||||
/// Find the model in the database by the given ID and replace it with the given.
|
/// Find the model in the database by the given ID and replace it with the given.
|
||||||
/// model.
|
/// model.
|
||||||
/// Expects a model. Sets the ID and Revision of the model.
|
/// Expects a model. Sets the ID and Revision of the model.
|
||||||
|
/// Returns the model (for convenience).
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
replaceById: function (id, model) {
|
replaceById: function (id, model) {
|
||||||
'use strict';
|
'use strict';
|
||||||
var data = model.forDB(),
|
var data = model.forDB(),
|
||||||
id_and_rev = this.collection.replace(id, data);
|
id_and_rev = this.collection.replace(id, data);
|
||||||
model.set(id_and_rev);
|
model.set(id_and_rev);
|
||||||
|
return model;
|
||||||
},
|
},
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue