© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
3 replies
floh

One To Many Relation, Dart Flutter, Database Swagger Codegen

Hey guys,
I am currently working on an project where i have a objectA which consists of many objectB´s. A basic one to many relationship.
Here is some pseudo sql code of the table:
create table objectA ( id )
create table objectB ( id, objectA_id references objectA id)
create table objectA ( id )
create table objectB ( id, objectA_id references objectA id)

and i to create those types with the swagger codegen: https://pub.dev/packages/swagger_dart_code_generator (please do not mind syntax. the classes have the json serialization annotation correctly)
class ObjectA() {
  id,
  List<ObjectB> objectBs,
}
class ObjectB() {
  id
}
class ObjectA() {
  id,
  List<ObjectB> objectBs,
}
class ObjectB() {
  id
}

but the codegen is generating smth like this
class ObjectA() {
  id,
}
class ObjectB() {
  id,
  objectA_ID,
}
class ObjectA() {
  id,
}
class ObjectB() {
  id,
  objectA_ID,
}

which means an postgrest call in dart like this wouldn´t work because objectA.fromJson never reads the value ObjectB:
final response = await _supabaseClient
          .from('objectA')
          .select(
            '''
            *,
            objectB (
              *
            )
            ''',
          )
          .eq('id', id)
          .single()
          .execute();
final data = response.data as Map<String, dynamic>;
return ObjectA.fromJson(data);
final response = await _supabaseClient
          .from('objectA')
          .select(
            '''
            *,
            objectB (
              *
            )
            ''',
          )
          .eq('id', id)
          .single()
          .execute();
final data = response.data as Map<String, dynamic>;
return ObjectA.fromJson(data);


any reccomendations or best practices on how to solve this?
Dart packages
swagger_dart_code_generator | Dart Package
Have you been turned into a problem with writing code for Http requests? This package can help. It has all of the Http and model codegen functionality you have been looking for.
swagger_dart_code_generator | Dart Package
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Recommended ORM for supabase + Dart Flutter
SupabaseSSupabase / help-and-questions
4y ago
Apollo Client Graphql : limit to one row relation one-to-many
SupabaseSSupabase / help-and-questions
3y ago
Many-to-many Relation is not Detected
SupabaseSSupabase / help-and-questions
14mo ago
How do I decode received data in Dart/Flutter?
SupabaseSSupabase / help-and-questions
3y ago