Does anyone know if there's a way to join tables w...
# flutter
m
Does anyone know if there's a way to join tables when using realtime subscriptions? Because with realtime now I can only return the listened table data, but I need to get other data from another table connected through a foreign key column In this code "payload.newRecord" only returns the tables row with foreign key column without joined data
Copy code
dart
  void _setupInsertSubscription() async {
    subscriptions['insert'] = _client.from(tableName).on(SupabaseEventTypes.insert, (payload) {
      final newList = ListModel.fromJson(payload.newRecord);
      lists = [newList, ...lists];
      notifyListeners();
    }).subscribe();
  }
v
You need to load the data from the other tables manually on every event. You could use a view if Supabase would support realtime on views. Sadly they don't.
m
I tried this
Copy code
dart
void _setupInsertSubscription() {
    subscriptions['insert'] =
        _client.from(tableName).on(SupabaseEventTypes.insert, (payload) async {
      final newList = ListModel.fromJson(payload.newRecord, false);
      final int marketId = payload.newRecord!['market_id'];
      final market = await _client
          .from('sl_markets')
          .select()
          .eq('id', marketId)
          .limit(1)
          .single()
          .execute();
      newList.market = Market.fromJson(market.data);
      lists = [newList, ...lists];
      notifyListeners();
    }).subscribe();
  }
but on the callback with the "async" keyword returns me an unhandle exception "Concurrent modification during iteration", but without async i cannot await 😅
a
did you have luck solving it?
2 Views