@@ -26,7 +26,7 @@ import type {
2626} from "~/orm/settings/settings-base.ts" ;
2727import type { InField } from "~/orm/field/field-def-types.ts" ;
2828import type { Choice } from "~/orm/field/types.ts" ;
29- import type { EntryConfig } from "~/orm/entry/types.ts" ;
29+ import type { EntryConfig , EntryConnection } from "~/orm/entry/types.ts" ;
3030import type { SettingsConfig } from "~/orm/settings/types.ts" ;
3131
3232import type { UserID } from "~/auth/types.ts" ;
@@ -137,6 +137,37 @@ export class Role {
137137 validateEntryType ( this , entryType ) ;
138138 registerFetchFields ( this , entryType ) ;
139139 }
140+ this . #setupEntryConnections( ) ;
141+ }
142+ #setupEntryConnections( ) : void {
143+ const connections = new Map < string , Array < EntryConnection > > ( ) ;
144+ for ( const entryType of this . entryTypes . values ( ) ) {
145+ const connectionsFields = entryType . fields . values ( ) . filter ( ( field ) =>
146+ field . type === "ConnectionField"
147+ ) ;
148+ for ( const field of connectionsFields ) {
149+ if ( ! connections . has ( field . entryType ) ) {
150+ connections . set ( field . entryType , [ ] ) ;
151+ }
152+ // const connectionEntryType = this.getEntryType(field.entryType);
153+ connections . get ( field . entryType ) ! . push ( {
154+ referencingEntry : entryType . name ,
155+ referencingEntryLabel : entryType . label ,
156+ referencingField : field . key ,
157+ referencingFieldLabel : field . label || field . key ,
158+ listFields : entryType . info . defaultListFields ,
159+ } ) ;
160+ }
161+ }
162+ for ( const [ entryName , connectionFields ] of connections . entries ( ) ) {
163+ const entryType = this . getEntryType ( entryName ) ;
164+
165+ entryType . connections = connectionFields ;
166+ entryType . info = {
167+ ...entryType . info ,
168+ connections : connectionFields ,
169+ } ;
170+ }
140171 }
141172 #setupSettingsTypes( ) : void {
142173 for ( const settingsType of this . settingsTypes . values ( ) ) {
0 commit comments