3030import com .amplifyframework .core .model .query .predicate .QueryPredicate ;
3131import com .amplifyframework .core .model .query .predicate .QueryPredicates ;
3232import com .amplifyframework .datastore .DataStoreException ;
33+ import com .amplifyframework .datastore .appsync .SerializedModel ;
3334import com .amplifyframework .datastore .storage .sqlite .adapter .SQLiteTable ;
3435import com .amplifyframework .logging .Logger ;
3536import com .amplifyframework .util .Empty ;
@@ -84,7 +85,7 @@ <T extends Model> List<Model> descendantsOf(Collection<T> root) {
8485 return new ArrayList <>();
8586 }
8687 Map <ModelSchema , Set <String >> modelMap = new LinkedHashMap <>();
87- ModelSchema rootSchema = registry .getModelSchemaForModelInstance ( root .iterator ().next ());
88+ ModelSchema rootSchema = registry .getModelSchemaForModelClass ( getModelName ( root .iterator ().next () ));
8889 Set <String > rootIds = new HashSet <>();
8990 for (T model : root ) {
9091 rootIds .add (model .getId ());
@@ -95,10 +96,18 @@ <T extends Model> List<Model> descendantsOf(Collection<T> root) {
9596 for (Map .Entry <ModelSchema , Set <String >> entry : modelMap .entrySet ()) {
9697 ModelSchema schema = entry .getKey ();
9798 for (String id : entry .getValue ()) {
98- // Create dummy model instance using just the ID and model type
99- String dummyJson = gson .toJson (Collections .singletonMap ("id" , id ));
100- Model dummyItem = gson .fromJson (dummyJson , schema .getModelClass ());
101- descendants .add (dummyItem );
99+ if (root .iterator ().next ().getClass () == SerializedModel .class ) {
100+ SerializedModel dummyItem = SerializedModel .builder ()
101+ .serializedData (Collections .singletonMap ("id" , id ))
102+ .modelSchema (schema )
103+ .build ();
104+ descendants .add (dummyItem );
105+ } else {
106+ // Create dummy model instance using just the ID and model type
107+ String dummyJson = gson .toJson (Collections .singletonMap ("id" , id ));
108+ Model dummyItem = gson .fromJson (dummyJson , schema .getModelClass ());
109+ descendants .add (dummyItem );
110+ }
102111 }
103112 }
104113 return descendants ;
@@ -172,4 +181,12 @@ private Cursor queryAll(
172181 final String [] bindings = sqlCommand .getBindingsAsArray ();
173182 return database .rawQuery (rawQuery , bindings );
174183 }
184+
185+ private String getModelName (@ NonNull Model model ) {
186+ if (model .getClass () == SerializedModel .class ) {
187+ return ((SerializedModel ) model ).getModelName ();
188+ } else {
189+ return model .getClass ().getSimpleName ();
190+ }
191+ }
175192}
0 commit comments