@@ -20,6 +20,7 @@ export const apply = ({
2020 functions,
2121 types,
2222 arrayTypes,
23+ detectOneToOneRelationships,
2324} : {
2425 schemas : PostgresSchema [ ]
2526 tables : Omit < PostgresTable , 'columns' > [ ]
@@ -30,6 +31,7 @@ export const apply = ({
3031 functions : PostgresFunction [ ]
3132 types : PostgresType [ ]
3233 arrayTypes : PostgresType [ ]
34+ detectOneToOneRelationships : boolean
3335} ) : string => {
3436 const columnsByTableId = columns
3537 . sort ( ( { name : a } , { name : b } ) => a . localeCompare ( b ) )
@@ -169,8 +171,11 @@ export interface Database {
169171 ( relationship ) => `{
170172 foreignKeyName: ${ JSON . stringify ( relationship . foreign_key_name ) }
171173 columns: ${ JSON . stringify ( relationship . columns ) }
172- isOneToOne: ${ relationship . is_one_to_one }
173- referencedRelation: ${ JSON . stringify ( relationship . referenced_relation ) }
174+ ${
175+ detectOneToOneRelationships
176+ ? `isOneToOne: ${ relationship . is_one_to_one } ;`
177+ : ''
178+ } referencedRelation: ${ JSON . stringify ( relationship . referenced_relation ) }
174179 referencedColumns: ${ JSON . stringify ( relationship . referenced_columns ) }
175180 }`
176181 ) }
@@ -238,8 +243,11 @@ export interface Database {
238243 ( relationship ) => `{
239244 foreignKeyName: ${ JSON . stringify ( relationship . foreign_key_name ) }
240245 columns: ${ JSON . stringify ( relationship . columns ) }
241- isOneToOne: ${ relationship . is_one_to_one }
242- referencedRelation: ${ JSON . stringify ( relationship . referenced_relation ) }
246+ ${
247+ detectOneToOneRelationships
248+ ? `isOneToOne: ${ relationship . is_one_to_one } ;`
249+ : ''
250+ } referencedRelation: ${ JSON . stringify ( relationship . referenced_relation ) }
243251 referencedColumns: ${ JSON . stringify ( relationship . referenced_columns ) }
244252 }`
245253 ) }
0 commit comments