-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed an error when creating a structure file #292
base: master
Are you sure you want to change the base?
Conversation
Fixed an error when creating structure.sql file for a database, when it is necessary to create a relation for tables that refer to each other.
Fixed an error when creating structure.sql file for a database, when it is necessary to create a relation for tables that refer to each other. Fixed ussues Metasql metarhia#291
@@ -201,6 +206,7 @@ const createEntity = (model, name) => { | |||
} | |||
sql[sql.length - 1] = sql[sql.length - 1].slice(0, -1); | |||
sql.push(');'); | |||
if (delayedKeys[name]) idx.push(delayedKeys[name]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use intermediate variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can:
const delayedKeyCurrent = delayedKeys[name];
if (delayedKeyCurrent) idx.push(delayedKeyCurrent);
@@ -183,7 +183,12 @@ const createEntity = (model, name) => { | |||
const ref = model.entities.get(def.type); | |||
if (!ref) throw new Error(`Unknown schema: ${def.type}`); | |||
const refId = ref.kind === 'registry'; | |||
idx.push(foreignKey(name, field, def, refId)); | |||
const fKey = foreignKey(name, field, def, refId); | |||
if (def.type in delayedKeys && def.type !== name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite without in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delayedKeys is an object with fields filled with nulls, so reading the property via [ key ] will not work. Therefore, I can change it to hasOwnProperty or Object.prototype.hasOwnProperty.call. Or suggest something else? Because hasOwnProperty is almost 100 times slower, although it is not critical here, but this is system code - that's why I used 'in'. Write what to put.
in dbms.js
for (const key of model.order) {
delayedKeys[key] = null;
}
Fixed an error when creating structure.sql file for a database, when it is necessary to create a relation for tables that refer to each other.
Fixed ussues Metasql #291
npm t
)npm run fmt
)