0

I'm using Drift(moor). When trying to get a sample of data using leftOuterJoin, the following situation happens: The table that I join via leftOuterJoin returns null as a value. I.e. leftOuterJoin itself works correctly but values from joined table are not read and return null. As a result, I get a row where 1 or 2 columns have null values (depending on what table I join) No one with such a situation is not faced?

final rows = await (select(favoritePlaces).join(
      [
        leftOuterJoin(
            cachedPlaces, cachedPlaces.id.equalsExp(favoritePlaces.placeId)),
      ],
    )).get();

parsedExpressions

1 Answers1

0
  1. Remove ".get()" from the last line.

  2. Add below lines after your code:

    final result = await rows.get();

    return result.map((resultRow) { return FavoritePlacesWithcachedPlaces( resultRow.readTable(favoritePlaces), resultRow.readTableOrNull(cachedPlaces), ); }).toList();

where FavoritePlacesWithcachedPlaces object is something like:

class FavoritePlacesWithcachedPlaces {

final FavoritePlaces favoritePlaces;
final CachedPlaces? cachedPlaces;

FavoritePlacesWithcachedPlaces (this.favoritePlaces, 
this.cachedPlaces);}

The key point is using "readTableOrNull".