mythix-orm-sql-base 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -126,12 +126,29 @@ class SQLConnectionBase extends ConnectionBase {
126
126
  if (!result)
127
127
  return {};
128
128
 
129
- let rows = result.rows;
129
+ let {
130
+ rows,
131
+ columns,
132
+ } = result;
130
133
  if (Nife.isEmpty(rows))
131
134
  return {};
132
135
 
136
+ const generateIDForModelFields = (data) => {
137
+ let keys = Object.keys(data || {}).sort();
138
+ let parts = [];
139
+
140
+ for (let i = 0, il = keys.length; i < il; i++) {
141
+ let key = keys[i];
142
+ let value = data[key];
143
+
144
+ parts.push(`${key}:${value}`);
145
+ }
146
+
147
+ return (!parts.length) ? null : parts.join(',');
148
+ };
149
+
133
150
  let context = queryEngine._getRawQueryContext();
134
- let fields = this.findAllFieldsFromFieldProjectionMap(result.columns);
151
+ let fields = this.findAllFieldsFromFieldProjectionMap(columns);
135
152
  let rootModelName = context.rootModelName;
136
153
  let modelData = {};
137
154
  let alreadyVisited = {};
@@ -200,20 +217,22 @@ class SQLConnectionBase extends ConnectionBase {
200
217
  if (!models)
201
218
  models = modelData[modelName] = [];
202
219
 
203
- if (pkFieldName) {
204
- let id = model[pkFieldName];
220
+ let id = model[pkFieldName];
221
+ if (id == null)
222
+ id = generateIDForModelFields(model);
205
223
 
206
- if (id != null) {
207
- let idKey = `${modelName}:${pkFieldName}:${id}`;
224
+ if (id != null) {
225
+ let idKey = `${modelName}:${pkFieldName}:${id}`;
208
226
 
209
- if (alreadyVisited[idKey] != null) {
210
- index = alreadyVisited[idKey];
211
- } else {
212
- index = alreadyVisited[idKey] = models.length;
213
- models.push(model);
214
- }
227
+ if (alreadyVisited[idKey] != null) {
228
+ index = alreadyVisited[idKey];
229
+ model = models[index];
230
+ } else {
231
+ index = alreadyVisited[idKey] = models.length;
232
+ models.push(model);
215
233
  }
216
234
  } else {
235
+ index = models.length;
217
236
  models.push(model);
218
237
  continue;
219
238
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mythix-orm-sql-base",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "SQL base support for Mythix ORM",
5
5
  "main": "lib/index.js",
6
6
  "type": "commonjs",