Replies: 1 comment
-
This is indeed not possible. Row classes always represent a single row, and if you have two tables, you'll have at least two rows involved. With the manager APIs, there's a pretty straightforward way to resolve joins. So you could keep the two separate classes and then return a third class (or a record) combining
In this case, you could turn the inner type ( class ObjectType {
final int id;
final String name;
const ObjectType({required this.id,required this.name});
factory ObjectType.fromJson(json) => ObjectType(json['id] as int, json['name'] as String);
Map<String, Object> toJson() => {'id': id, 'name': name};
} And then define the table for @UseRowClass(Object)
class Objects extends Table {
IntColumn get id => integer().autoIncrement()()
// ...
TextColumn get type => text().map(TypeConverter.json(fromJson: ObjectType.fromJson, toJson: (o) => o.toJson()))();
} |
Beta Was this translation helpful? Give feedback.
-
i have a class and one of the fields is an object of another class , such as this example :
i want to use them as custom row classes while having two seperate tables, one for objects, the other for objectTypes .
if it's not possible, the how about making them insertable into one table ? i don't see a way of implementing type converters in this scenario.
ps: i would appreciate if u had alternative suggestions about organizing data that might have such structure.
Beta Was this translation helpful? Give feedback.
All reactions