simolus3 / drift

Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.
https://drift.simonbinder.eu/
MIT License
2.66k stars 372 forks source link

Generated code "parameter isn't a function or method and can't be invoked." #3251

Closed emreakcan closed 1 month ago

emreakcan commented 1 month ago

Describe the bug

Code generation generates the following

  $$ShotTracingTableTableProcessedTableManager
      get InteractiveMapHolesTournamentId {
    final manager =
        $$ShotTracingTableTableTableManager($_db, $_db.shotTracingTable)
            .filter((f) => f.tournamentId.tournamentId($_item.tournamentId));

    final cache = $_typedResult
        .readTableOrNull(_InteractiveMapHolesTournamentIdTable($_db));
    return ProcessedTableManager(
        manager.$state.copyWith(prefetchedData: cache));
  }

Which results in

lib/database/database.g.dart:67382:55: Error: 'tournamentId' isn't a function or method and can't be invoked.
            .filter((f) => f.tournamentId.tournamentId($_item.tournamentId));
                                                      ^^^^^^^^^^^^
lib/database/database.g.dart:67787:38: Error: 'tournamentId' isn't a function or method and can't be invoked.
        .filter((f) => f.tournamentId($_item.tournamentId!));
                                     ^^^^^^^^^^^^
Target kernel_snapshot_program failed: Exception

Our table looks like

@DataClassName('ShotTracingEntity')
class ShotTracingTable extends Table {
  @ReferenceName('InteractiveMapHolesTournamentId')
  TextColumn get tournamentId =>
      text().references(InteractiveMapHolesTable, #tournamentId)();

  IntColumn get roundNumber => integer()();

  TextColumn get playerId => text()();

  @ReferenceName('InteractiveMapHolesHoleId')
  IntColumn get holeNumber =>
      integer().references(InteractiveMapHolesTable, #holeId)();

  IntColumn get strokeNumber => integer()();

  TextColumn get clubUsed => text()();

  TextColumn get description => text().nullable()();

  TextColumn get strokeType => text()();

  RealColumn get restingPointX => real().nullable()();

  RealColumn get restingPointY => real().nullable()();

  RealColumn get restingPointZ => real().nullable()();

  RealColumn get distanceToPin => real().nullable()();

  RealColumn get distanceTravelled => real().nullable()();

  RealColumn get tempC => real().nullable()();

  RealColumn get windSpeed => real().nullable()();

  IntColumn get windDirectionDegrees => integer().nullable()();

  TextColumn get windDirection => text()();

  RealColumn get humidity => real().nullable()();

  BoolColumn get isAroundGreen =>
      boolean().withDefault(const Constant(false))();

  BoolColumn get inWaterHazard =>
      boolean().withDefault(const Constant(false))();

  BoolColumn get inTheHole => boolean().withDefault(const Constant(false))();

  @override
  Set<Column> get primaryKey => {
        tournamentId,
        roundNumber,
        playerId,
        holeNumber,
        strokeNumber,
      };
}

We are using latest version, and latest version of the build runner.

dickermoshe commented 1 month ago

I really want to get this fixed ASAP. Could you post the InteractiveMapHolesTable table too?

For now, If you don't plan on using the manager api, you can disable it's generation with

emreakcan commented 1 month ago

I really want to get this fixed ASAP. Could you post the InteractiveMapHolesTable table too?

For now, If you don't plan on using the manager api, you can disable it's generation with

Here is the table

@DataClassName('InteractiveMapHolesEntity')
class InteractiveMapHolesTable extends Table {
  TextColumn get tournamentId =>
      text().references(InteractiveMapsTable, #tournamentId)();

  RealColumn get topLeftX => real()();

  RealColumn get topLeftY => real()();

  RealColumn get bottomRightX => real()();

  RealColumn get bottomRightY => real()();

  TextColumn get imageUrl => text()();

  IntColumn get holeId => integer()();

  TextColumn get heroUrl => text().nullable()();

  TextColumn get worldFile => text()();

  @override
  Set<Column> get primaryKey => {tournamentId, holeId};
}
emreakcan commented 1 month ago

It is working after I disabled manager api

dickermoshe commented 1 month ago

Caused by having a foreign key on another foreign key

ShotTracingTable.tournamentId->InteractiveMapHolesTable.tournamentId->InteractiveMapsTable.tournamentId

An edge case I didn't consider