stormberry icon indicating copy to clipboard operation
stormberry copied to clipboard

Insert/Update ManyToMany relations

Open f3l1x98 opened this issue 2 years ago • 2 comments

At the moment it is not possible to update ManyToMany ~~, ManyToOne or OneToMany~~ relations, because the insert/update models are missing the required attributes (and query). That is required, because there is no direct access to the JoinTables (in case of ManyToMany).

Example

// game_model.dart:
abstract class Game {
  @PrimaryKey()
  @AutoIncrement()
  int get id;
  List<Genre> get genres;
  @BindTo(#sequel)
  Game? get prequel;
  @BindTo(#prequel)
  Game? get sequel;
}

// genre_model.dart:
abstract class Genre {
  @PrimaryKey()
  @AutoIncrement()
  int get id;
  String get name;
  String? get description;
  List<Game> get games;
}

generates:

// game_model.schema.dart:
// [...]
class GameInsertRequest {
  GameInsertRequest({
    this.prequelId,
  });

  int? prequelId;
}

class GameUpdateRequest {
  GameUpdateRequest({
    required this.id,
    this.prequelId,
  });

  int id;
  int? prequelId;
}

// genre_model.schema.dart:
// [...]
class GenreInsertRequest {
  GenreInsertRequest({
    required this.name,
    this.description,
  });

  String name;
  String? description;
}

class GenreUpdateRequest {
  GenreUpdateRequest({
    required this.id,
    this.name,
    this.description,
  });

  int id;
  String? name;
  String? description;
}

f3l1x98 avatar Mar 06 '23 16:03 f3l1x98

I see the problem with many-to-many and missing access to join tables. But can you elaborate whats missing with many-to-one and one-to-many?

schultek avatar Mar 07 '23 07:03 schultek

I see the problem with many-to-many and missing access to join tables. But can you elaborate whats missing with many-to-one and one-to-many?

My bad. ManyToOne and OneToMany works, just forgot that I changed one of my ManyToOne relations to ManyToMany.

f3l1x98 avatar Mar 07 '23 11:03 f3l1x98