Skip to content

Commit

Permalink
data.RecordFactory: createRecordClass() => add a 2nd param to enforce…
Browse files Browse the repository at this point in the history
… class overwrites #6252
  • Loading branch information
tobiu committed Jan 18, 2025
1 parent afc9793 commit b7081bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/data/Model.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ class Model extends Base {
*/
afterSetFields(value, oldValue) {
if (value) {
this.updateFieldsMap(value);
let me = this;

me.updateFieldsMap(value);

// Fields can get changed multiple times before the model instance is getting constructed.
// We only need the latest state before construction & honor run-time changes.
if (this.isConstructed) {
RecordFactory.createRecordClass(value)
if (me.isConstructed) {
RecordFactory.createRecordClass(me, true)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/data/RecordFactory.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,16 @@ class RecordFactory extends Base {

/**
* @param {Neo.data.Model} model
* @param {Boolean} overwrite=false
* @returns {Object}
*/
createRecordClass(model) {
createRecordClass(model, overwrite=false) {
if (model instanceof Model) {
let className = `${this.recordNamespace}.${model.className}.${model.id}`,
ns = Neo.ns(className),
key, nsArray, cls;

if (!ns) {
if (!ns || overwrite) {
nsArray = className.split('.');
key = nsArray.pop();
ns = Neo.ns(nsArray, true);
Expand Down

0 comments on commit b7081bf

Please sign in to comment.