Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
6f050ba
Automatically convert files in data to the format understood by djang…
Apr 2, 2021
bf6407a
New models will get a negative id by default instead of null, with up…
Jun 28, 2021
849c0cd
v0.28.3
Jun 28, 2021
744cb65
v0.28.4
Jun 28, 2021
dfff896
Merge branch 'isnew-for-negative-ids' into T32139-default-negative-id…
Jun 28, 2021
0fb001d
v0.29.0
Jun 28, 2021
7dda13e
Related models will still get id of null to indicate relation is empty
Jun 28, 2021
e27cce9
Add more tests showcasing clearing behaviour also after copying
Jun 28, 2021
6ad90ae
v0.28.4
Jul 2, 2021
d479d3a
Merge remote-tracking branch 'origin/isnew-for-negative-ids' into isn…
Jul 7, 2021
4c39b2f
Merge branch 'isnew-for-negative-ids' into T32139-default-negative-id…
Jul 7, 2021
87c1df7
v0.29.1
Jul 7, 2021
5f90823
Create new negative id on clear
Jul 7, 2021
14eed14
Fix review comments from Daan
Jul 26, 2021
c125b0e
Test in jsdom environment so that we can use Blob/FormData
Jul 26, 2021
725c2cf
Add tests
Jul 26, 2021
be18b90
Add documentation
Jul 26, 2021
ca5532f
fix docs
Jul 26, 2021
e58a9f5
Merge branch 'master' into files-in-request-body
Aug 23, 2021
66b1c14
add tests to check if files convert after model.save
Aug 23, 2021
fbe2e80
Improve test
Aug 24, 2021
a2ca2ac
Improve both tests
Aug 24, 2021
d7ff52e
Automatically convert files in data to the format understood by djang…
Apr 2, 2021
8d5efa9
Test in jsdom environment so that we can use Blob/FormData
Jul 26, 2021
b904268
Add tests
Jul 26, 2021
b1fa3ff
Merge remote-tracking branch 'CY/files-in-request-body' into files-in…
Oct 25, 2021
10160ea
add tests to check if files convert after model.save
Aug 23, 2021
204beaf
Improve test
Aug 24, 2021
604c335
Improve both tests
Aug 24, 2021
a64c093
Fix frontend_lint and update node version
Oct 25, 2021
0c2f2ce
Merge remote-tracking branch 'CY/files-in-request-body' into files-in…
Oct 25, 2021
97def3e
Merge pull request #123 from Bilonan/files-in-request-body
abzainuddin Oct 25, 2021
36b0d2a
Merge pull request #103 from CodeYellowBV/files-in-request-body
abzainuddin Nov 26, 2021
3f916bb
v0.28.3
abzainuddin Nov 26, 2021
60f3f8b
v0.28.4
abzainuddin Nov 26, 2021
dcb8690
add check if relation is defined
Nov 29, 2021
87aa1f7
build
Nov 29, 2021
f7dc23f
Add comment for relation check
Nov 29, 2021
82ff876
Add test "save all with not defined relation error"
Nov 30, 2021
fe5418c
add snapshot
Nov 30, 2021
1e70ed4
Merge pull request #125 from Bilonan/T34782-relations-error
abzainuddin Nov 30, 2021
ee852d2
Fix styling of some comments, and added a migration guide for convert…
Feb 28, 2022
445474d
Merge branch 'health_master' into T32139-default-negative-ids-for-new…
Feb 28, 2022
7de2476
build es files
Feb 28, 2022
ccc3e1d
v0.29.2
Feb 28, 2022
34cedfc
v0.30.0
Feb 28, 2022
80a82f2
Merge remote-tracking branch 'origin-cy/master' into T32139-default-n…
Feb 28, 2022
d7897be
add failing test for inconsistent ordering
Mar 3, 2022
b3855df
fix instable ordering in relations
Mar 3, 2022
5a66e98
update build
Mar 3, 2022
6e9a5fc
Improve running time of repository parsing
Mar 4, 2022
cec7709
Merge pull request #129 from CodeYellowBV/fix_with_sorting_bug
Mar 4, 2022
65ea570
Merge remote-tracking branch 'origin-cy/master' into T32139-default-n…
Mar 28, 2022
126db33
build es files
Mar 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions dist/mobx-spine.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () {
}

/**
* Gives the model the internal id. This is useful if you have a new model that you want to give an id so
* that it can be referred to in a relation.
* Gives the model the internal id, meaning that it will keep the set id of the model or it will receive a negative
* id if the id is null. This is useful if you have a new model that you want to give an id so that it can be
* referred to in a relation.
*/

}, {
Expand Down Expand Up @@ -925,7 +926,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () {

/**
* A model is considered new if it does not have an id, or if the id is a negative integer.
* @returns {boolean} True if the model id is not set or a negative integer
* @returns {boolean} - True if the model id is not set or a negative integer
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo?

*/

}, {
Expand Down Expand Up @@ -997,6 +998,16 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () {
if (options.relations) {
this.__parseRelations(options.relations);
}

// The model will automatically be assigned a negative id, the id will still be overridden if it is supplied in the data
this.assignInternalId();

// We want our id to remain negative on a clear, only if it was not created with the id set to null
// which is usually the case when the object is a related model in which case we want the id to be reset to null
if (data && data[this.constructor.primaryKey] !== null || !data) {
this.__originalAttributes[this.constructor.primaryKey] = this[this.constructor.primaryKey];
}

if (data) {
this.parse(data);
}
Expand Down Expand Up @@ -1045,7 +1056,10 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () {
if (RelModel.prototype instanceof Store) {
return new RelModel(options);
}
return new RelModel(null, options);
// If we have a related model, we want to force the related model to have id null as that means there is no model set
var newModelData = {};
newModelData[RelModel.primaryKey] = null;
return new RelModel(newModelData, options);
}));
}

Expand Down Expand Up @@ -1910,7 +1924,13 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () {
var _this19 = this;

lodash.forIn(this.__originalAttributes, function (value, key) {
_this19[key] = value;
// If it is our primary key, and the primary key is negative, we generate a new negative pk, else we set it
// to the value
if (key === _this19.constructor.primaryKey && value < 0) {
_this19[key] = -1 * lodash.uniqueId();
} else {
_this19[key] = value;
}
});

this.__activeCurrentRelations.forEach(function (currentRel) {
Expand Down
30 changes: 25 additions & 5 deletions dist/mobx-spine.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () {
}

/**
* Gives the model the internal id. This is useful if you have a new model that you want to give an id so
* that it can be referred to in a relation.
* Gives the model the internal id, meaning that it will keep the set id of the model or it will receive a negative
* id if the id is null. This is useful if you have a new model that you want to give an id so that it can be
* referred to in a relation.
*/

}, {
Expand Down Expand Up @@ -919,7 +920,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () {

/**
* A model is considered new if it does not have an id, or if the id is a negative integer.
* @returns {boolean} True if the model id is not set or a negative integer
* @returns {boolean} - True if the model id is not set or a negative integer
*/

}, {
Expand Down Expand Up @@ -991,6 +992,16 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () {
if (options.relations) {
this.__parseRelations(options.relations);
}

// The model will automatically be assigned a negative id, the id will still be overridden if it is supplied in the data
this.assignInternalId();

// We want our id to remain negative on a clear, only if it was not created with the id set to null
// which is usually the case when the object is a related model in which case we want the id to be reset to null
if (data && data[this.constructor.primaryKey] !== null || !data) {
this.__originalAttributes[this.constructor.primaryKey] = this[this.constructor.primaryKey];
}

if (data) {
this.parse(data);
}
Expand Down Expand Up @@ -1039,7 +1050,10 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () {
if (RelModel.prototype instanceof Store) {
return new RelModel(options);
}
return new RelModel(null, options);
// If we have a related model, we want to force the related model to have id null as that means there is no model set
var newModelData = {};
newModelData[RelModel.primaryKey] = null;
return new RelModel(newModelData, options);
}));
}

Expand Down Expand Up @@ -1904,7 +1918,13 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () {
var _this19 = this;

forIn(this.__originalAttributes, function (value, key) {
_this19[key] = value;
// If it is our primary key, and the primary key is negative, we generate a new negative pk, else we set it
// to the value
if (key === _this19.constructor.primaryKey && value < 0) {
_this19[key] = -1 * uniqueId();
} else {
_this19[key] = value;
}
});

this.__activeCurrentRelations.forEach(function (currentRel) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-spine",
"version": "0.28.4",
"version": "0.29.1",
"license": "ISC",
"author": "Kees Kluskens <kees@webduck.nl>",
"description": "MobX with support for models, relations and an API.",
Expand Down
28 changes: 23 additions & 5 deletions src/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ export default class Model {
}

/**
* Gives the model the internal id. This is useful if you have a new model that you want to give an id so
* that it can be referred to in a relation.
* Gives the model the internal id, meaning that it will keep the set id of the model or it will receive a negative
* id if the id is null. This is useful if you have a new model that you want to give an id so that it can be
* referred to in a relation.
*/
assignInternalId() {
this[this.constructor.primaryKey] = this.getInternalId()
Expand All @@ -142,7 +143,7 @@ export default class Model {

/**
* A model is considered new if it does not have an id, or if the id is a negative integer.
* @returns {boolean} True if the model id is not set or a negative integer
* @returns {boolean} - True if the model id is not set or a negative integer
*/
@computed
get isNew() {
Expand Down Expand Up @@ -212,6 +213,16 @@ export default class Model {
if (options.relations) {
this.__parseRelations(options.relations);
}

// The model will automatically be assigned a negative id, the id will still be overridden if it is supplied in the data
this.assignInternalId()

// We want our id to remain negative on a clear, only if it was not created with the id set to null
// which is usually the case when the object is a related model in which case we want the id to be reset to null
if ((data && data[this.constructor.primaryKey] !== null) || !data){
this.__originalAttributes[this.constructor.primaryKey] = this[this.constructor.primaryKey]
}

if (data) {
this.parse(data);
}
Expand Down Expand Up @@ -265,7 +276,8 @@ export default class Model {
if (RelModel.prototype instanceof Store) {
return new RelModel(options);
}
return new RelModel(null, options);
// If we have a related model, we want to force the related model to have id null as that means there is no model set
return new RelModel({ [RelModel.primaryKey]: null }, options);
})
);
}
Expand Down Expand Up @@ -1096,7 +1108,13 @@ export default class Model {
@action
clear() {
forIn(this.__originalAttributes, (value, key) => {
this[key] = value;
// If it is our primary key, and the primary key is negative, we generate a new negative pk, else we set it
// to the value
if (key === this.constructor.primaryKey && value < 0){
this[key] = -1 * uniqueId();
} else {
this[key] = value;
}
});

this.__activeCurrentRelations.forEach(currentRel => {
Expand Down
Loading