I have two tables: students and groups. I need to implement a one-to-many relationship of these tables so that when I create a student I have a list of groups from the database and I can add the student to a specific group. And so that when I click on a group, I have a list of students who are part of it. How can i do this? Group table and group model:
class GroupDB extends Table {
IntColumn get id => integer().autoIncrement().nullable()();
TextColumn get groupName => text().named('group_name')();
}
class Group {
Group({
this.id,
required this.groupName,
});
int? id;
String groupName;
}
Student table and model:
class StudentsDB extends TableWithIntId {
IntColumn get id => integer().autoIncrement().nullable()();
TextColumn get firstName => text().named('first_name')();
TextColumn get lastName => text().named('last_name')();
}
class Student {
Student({
this.id,
required this.firstName,
required this.lastName,
});
int? id;
String firstName;
String lastName;
}