@@ -76,8 +76,28 @@ export function syncEnums({
7676 . filter ( ( d ) => isEnum ( d ) )
7777 . forEach ( ( d ) => {
7878 const factory = new EnumFactory ( ) . setName ( d . name ) ;
79+ // Copy enum-level comments
80+ if ( d . comments ?. length ) {
81+ factory . update ( { comments : [ ...d . comments ] } ) ;
82+ }
83+ // Copy enum-level attributes (@@map, @@schema, etc.)
84+ if ( d . attributes ?. length ) {
85+ factory . update ( { attributes : [ ...d . attributes ] } ) ;
86+ }
87+ // Copy fields with their attributes and comments
7988 d . fields . forEach ( ( v ) => {
80- factory . addField ( ( builder ) => builder . setName ( v . name ) ) ;
89+ factory . addField ( ( builder ) => {
90+ builder . setName ( v . name ) ;
91+ // Copy field-level comments
92+ if ( v . comments ?. length ) {
93+ v . comments . forEach ( ( c ) => builder . addComment ( c ) ) ;
94+ }
95+ // Copy field-level attributes (@map, etc.)
96+ if ( v . attributes ?. length ) {
97+ builder . update ( { attributes : [ ...v . attributes ] } ) ;
98+ }
99+ return builder ;
100+ } ) ;
81101 } ) ;
82102 model . declarations . push ( factory . get ( { $container : model } ) ) ;
83103 } ) ;
@@ -322,8 +342,10 @@ export function syncTable({
322342 ) ;
323343 }
324344
325- const uniqueColumns = table . columns . filter ( ( c ) => c . unique || c . pk ) ;
326- if ( uniqueColumns . length === 0 ) {
345+ const hasUniqueConstraint =
346+ table . columns . some ( ( c ) => c . unique || c . pk ) ||
347+ table . indexes . some ( ( i ) => i . unique ) ;
348+ if ( ! hasUniqueConstraint ) {
327349 modelFactory . addAttribute ( ( a ) => a . setDecl ( getAttributeRef ( '@@ignore' , services ) ) ) ;
328350 modelFactory . comments . push (
329351 '/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Zenstack Client.' ,
@@ -415,14 +437,14 @@ export function syncRelation({
415437 services,
416438 options,
417439 selfRelation,
418- simmilarRelations ,
440+ similarRelations ,
419441} : {
420442 model : Model ;
421443 relation : Relation ;
422444 services : ZModelServices ;
423445 options : PullOptions ;
424446 //self included
425- simmilarRelations : number ;
447+ similarRelations : number ;
426448 selfRelation : boolean ;
427449} ) {
428450 const idAttribute = getAttributeRef ( '@id' , services ) ;
@@ -431,7 +453,7 @@ export function syncRelation({
431453 const fieldMapAttribute = getAttributeRef ( '@map' , services ) ;
432454 const tableMapAttribute = getAttributeRef ( '@@map' , services ) ;
433455
434- const includeRelationName = selfRelation || simmilarRelations > 0 ;
456+ const includeRelationName = selfRelation || similarRelations > 0 ;
435457
436458 if ( ! idAttribute || ! uniqueAttribute || ! relationAttribute || ! fieldMapAttribute || ! tableMapAttribute ) {
437459 throw new Error ( 'Cannot find required attributes in the model.' ) ;
@@ -456,15 +478,15 @@ export function syncRelation({
456478
457479 const fieldPrefix = / [ 0 - 9 ] / g. test ( sourceModel . name . charAt ( 0 ) ) ? '_' : '' ;
458480
459- const relationName = `${ relation . table } ${ simmilarRelations > 0 ? `_${ relation . column } ` : '' } To${ relation . references . table } ` ;
481+ const relationName = `${ relation . table } ${ similarRelations > 0 ? `_${ relation . column } ` : '' } To${ relation . references . table } ` ;
460482
461483 const sourceNameFromReference = sourceField . name . toLowerCase ( ) . endsWith ( 'id' ) ? `${ resolveNameCasing ( "camel" , sourceField . name . slice ( 0 , - 2 ) ) . name } ${ relation . type === 'many' ? 's' : '' } ` : undefined ;
462484
463485 const sourceFieldFromReference = sourceModel . fields . find ( ( f ) => f . name === sourceNameFromReference ) ;
464486
465487 let { name : sourceFieldName } = resolveNameCasing (
466488 options . fieldCasing ,
467- simmilarRelations > 0
489+ similarRelations > 0
468490 ? `${ fieldPrefix } ${ sourceModel . name . charAt ( 0 ) . toLowerCase ( ) } ${ sourceModel . name . slice ( 1 ) } _${ relation . column } `
469491 : `${ ( ! sourceFieldFromReference ? sourceNameFromReference : undefined ) || resolveNameCasing ( "camel" , targetModel . name ) . name } ${ relation . type === 'many' ? 's' : '' } ` ,
470492 ) ;
@@ -523,7 +545,7 @@ export function syncRelation({
523545 const oppositeFieldPrefix = / [ 0 - 9 ] / g. test ( targetModel . name . charAt ( 0 ) ) ? '_' : '' ;
524546 const { name : oppositeFieldName } = resolveNameCasing (
525547 options . fieldCasing ,
526- simmilarRelations > 0
548+ similarRelations > 0
527549 ? `${ oppositeFieldPrefix } ${ sourceModel . name . charAt ( 0 ) . toLowerCase ( ) } ${ sourceModel . name . slice ( 1 ) } _${ relation . column } `
528550 : `${ resolveNameCasing ( "camel" , sourceModel . name ) . name } ${ relation . references . type === 'many' ? 's' : '' } ` ,
529551 ) ;
0 commit comments