@ronin/compiler 0.14.0-leo-ron-1099-1-experimental-315 → 0.14.0-leo-ron-1099-1-experimental-317

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/dist/index.d.ts CHANGED
@@ -169,7 +169,7 @@ type ModelFieldBasics = {
169
169
  * The value that should be inserted into the field in the case that no value was
170
170
  * explicitly provided for it when a record is created.
171
171
  */
172
- defaultValue?: unknown;
172
+ defaultValue?: Expression | unknown;
173
173
  /**
174
174
  * An expression that should be evaluated to form the value of the field. The
175
175
  * expression can either be VIRTUAL (evaluated whenever a record is read) or STORED
package/dist/index.js CHANGED
@@ -1227,15 +1227,59 @@ var addDefaultModelPresets = (list, model) => {
1227
1227
  const defaultPresets = [];
1228
1228
  for (const field of model.fields || []) {
1229
1229
  if (field.type === "link" && !field.slug.startsWith("ronin.")) {
1230
- const relatedModel = getModelBySlug(list, field.target);
1231
- if (field.kind === "many") continue;
1230
+ const targetModel = getModelBySlug(list, field.target);
1231
+ if (field.kind === "many") {
1232
+ const systemModel = list.find(({ system }) => {
1233
+ return system?.model === model.id && system?.associationSlug === field.slug;
1234
+ });
1235
+ if (!systemModel) continue;
1236
+ const preset = {
1237
+ instructions: {
1238
+ // Perform a LEFT JOIN that adds the associative table.
1239
+ including: {
1240
+ [field.slug]: {
1241
+ [QUERY_SYMBOLS.QUERY]: {
1242
+ get: {
1243
+ [systemModel.pluralSlug]: {
1244
+ // ON associative_table.source = origin_model.id
1245
+ with: {
1246
+ source: {
1247
+ [QUERY_SYMBOLS.EXPRESSION]: `${QUERY_SYMBOLS.FIELD_PARENT}id`
1248
+ }
1249
+ },
1250
+ // Perform a LEFT JOIN that adds the target model table.
1251
+ including: {
1252
+ [QUERY_SYMBOLS.QUERY]: {
1253
+ get: {
1254
+ [targetModel.slug]: {
1255
+ // ON target_model.id = associative_table.target
1256
+ with: {
1257
+ id: {
1258
+ [QUERY_SYMBOLS.EXPRESSION]: `${QUERY_SYMBOLS.FIELD_PARENT}target`
1259
+ }
1260
+ }
1261
+ }
1262
+ }
1263
+ }
1264
+ }
1265
+ }
1266
+ }
1267
+ }
1268
+ }
1269
+ }
1270
+ },
1271
+ slug: field.slug
1272
+ };
1273
+ defaultPresets.push(preset);
1274
+ continue;
1275
+ }
1232
1276
  defaultPresets.push({
1233
1277
  instructions: {
1234
1278
  including: {
1235
1279
  [field.slug]: {
1236
1280
  [QUERY_SYMBOLS.QUERY]: {
1237
1281
  get: {
1238
- [relatedModel.slug]: {
1282
+ [targetModel.slug]: {
1239
1283
  with: {
1240
1284
  // Compare the `id` field of the related model to the link field on
1241
1285
  // the root model (`field.slug`).
@@ -1254,6 +1298,7 @@ var addDefaultModelPresets = (list, model) => {
1254
1298
  }
1255
1299
  }
1256
1300
  const childModels = list.map((subModel) => {
1301
+ if (subModel.system?.associationSlug) return null;
1257
1302
  const field = subModel.fields?.find((field2) => {
1258
1303
  return field2.type === "link" && field2.target === model.slug;
1259
1304
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.14.0-leo-ron-1099-1-experimental-315",
3
+ "version": "0.14.0-leo-ron-1099-1-experimental-317",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {