metal-orm 1.1.4 → 1.1.5

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metal-orm",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "engines": {
@@ -277,6 +277,8 @@ const renderEntityClassLines = ({ table, className, naming, relations, resolveCl
277
277
  lines.push(`@Entity(${entityOpts})`);
278
278
  lines.push(`export class ${className} {`);
279
279
 
280
+ const columnPropertyNames = new Set(table.columns.map(col => sanitizePropertyName(col.name)));
281
+
280
282
  for (const col of table.columns) {
281
283
  const propertyName = sanitizePropertyName(col.name);
282
284
  const rendered = renderColumnExpression(col, table.primaryKey, table.schema, defaultSchema, propertyName);
@@ -298,10 +300,31 @@ const renderEntityClassLines = ({ table, className, naming, relations, resolveCl
298
300
  const isSelfRefHasMany = (rel) =>
299
301
  treeConfig && rel.kind === 'hasMany' && rel.foreignKey === treeParentFK && isSelfRef(rel.target);
300
302
 
303
+ // Track used relation property names to avoid duplicates among relations themselves
304
+ const usedRelationProps = new Set();
305
+
301
306
  for (const rel of relations) {
302
307
  const targetClass = resolveClassName(rel.target);
303
308
  if (!targetClass) continue;
304
- const propName = naming.applyRelationOverride(className, rel.property);
309
+ let propName = naming.applyRelationOverride(className, rel.property);
310
+
311
+ // If the generated property name conflicts with a column property, fall back to
312
+ // using the camelCased target class name. This happens when a FK column has no
313
+ // "_id" suffix (e.g. "instancia", "criador") so the naming strategy derives the
314
+ // same name for both the column and the relation.
315
+ if (columnPropertyNames.has(propName)) {
316
+ const fallback = naming.toCamelCase(
317
+ naming.singularize(naming.normalizeTableName(rel.target))
318
+ );
319
+ propName = fallback;
320
+ }
321
+
322
+ // Resolve any remaining duplicate among relation properties by appending the FK name
323
+ if (usedRelationProps.has(propName)) {
324
+ propName = `${propName}_${naming.toCamelCase(rel.foreignKey)}`;
325
+ }
326
+ usedRelationProps.add(propName);
327
+
305
328
  switch (rel.kind) {
306
329
  case 'belongsTo':
307
330
  // For tree tables, replace @BelongsTo for parent with @TreeParent