@@ -13,6 +13,7 @@ import {
1313 alwaysSyncedPropertyTypes ,
1414 assertFieldTypeMatchesPropertyType ,
1515 type FieldInfo ,
16+ fetchRelationIdsForPageProperty ,
1617 getDatabase ,
1718 getDatabaseFieldsInfo ,
1819 getDatabaseItems ,
@@ -241,7 +242,7 @@ export async function syncCollection(
241242 continue
242243 }
243244
244- const fieldEntry = getFieldDataEntryForProperty ( property , field )
245+ const fieldEntry = await getFieldDataEntryForProperty ( property , field , item . id )
245246 if ( fieldEntry ) {
246247 fieldData [ field . id ] = fieldEntry
247248 } else {
@@ -624,10 +625,11 @@ export function fieldsInfoToCollectionFields(
624625 return fields
625626}
626627
627- export function getFieldDataEntryForProperty (
628+ async function getFieldDataEntryForProperty (
628629 property : PageObjectResponse [ "properties" ] [ string ] ,
629- field : ManagedCollectionFieldInput
630- ) : FieldDataEntryInput | null {
630+ field : ManagedCollectionFieldInput ,
631+ itemId : string
632+ ) : Promise < FieldDataEntryInput | null > {
631633 switch ( property . type ) {
632634 case "checkbox" : {
633635 return { type : "boolean" , value : property . checkbox }
@@ -691,7 +693,14 @@ export function getFieldDataEntryForProperty(
691693 }
692694 case "relation" : {
693695 if ( field . type === "multiCollectionReference" ) {
694- return { type : "multiCollectionReference" , value : property . relation . map ( ( { id } ) => id ) }
696+ let relationItemIds : string [ ] = [ ]
697+ if ( "has_more" in property && property . has_more ) {
698+ relationItemIds = await fetchRelationIdsForPageProperty ( itemId , property . id )
699+ } else {
700+ relationItemIds = property . relation . map ( ( { id } ) => id )
701+ }
702+
703+ return { type : "multiCollectionReference" , value : relationItemIds }
695704 } else if ( field . type === "collectionReference" ) {
696705 return { type : "collectionReference" , value : property . relation [ 0 ] ?. id ?? null }
697706 }
0 commit comments