@stonyx/orm 0.2.1-alpha.30 → 0.2.1-alpha.32

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.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "stonyx-async",
5
5
  "stonyx-module"
6
6
  ],
7
- "version": "0.2.1-alpha.30",
7
+ "version": "0.2.1-alpha.32",
8
8
  "description": "",
9
9
  "main": "src/main.js",
10
10
  "type": "module",
package/src/belongs-to.js CHANGED
@@ -21,9 +21,13 @@ export default function belongsTo(modelName) {
21
21
  const modelStore = store.get(modelName);
22
22
 
23
23
  // Try to get existing record
24
- const output = typeof rawData === 'object'
25
- ? createRecord(modelName, rawData, options)
26
- : modelStore.get(rawData);
24
+ let output;
25
+
26
+ if (typeof rawData === 'object') {
27
+ output = createRecord(modelName, rawData, options);
28
+ } else if (modelStore) {
29
+ output = modelStore.get(rawData);
30
+ }
27
31
 
28
32
  // If not found and is a string ID, register as pending
29
33
  if (!output && typeof rawData !== 'object') {
package/src/has-many.js CHANGED
@@ -27,6 +27,10 @@ export default function hasMany(modelName) {
27
27
  let record;
28
28
 
29
29
  if (typeof elementData !== 'object') {
30
+ if (!modelStore) {
31
+ return queuePendingRelationship(pendingRelationshipQueue, pendingRelationships, modelName, elementData);
32
+ }
33
+
30
34
  record = modelStore.get(elementData);
31
35
 
32
36
  if (!record) {
@@ -23,6 +23,8 @@ export function createRecord(modelName, rawData={}, userOptions={}) {
23
23
  const globalRelationships = relationships.get('global');
24
24
  const pendingRelationships = relationships.get('pending');
25
25
 
26
+ if (!modelStore) throw new Error(`Model store for '${modelName}' is not registered. Ensure the model is defined before creating records.`);
27
+
26
28
  assignRecordId(modelName, rawData);
27
29
  if (modelStore.has(rawData.id)) return modelStore.get(rawData.id);
28
30