0

I am going to be working with sqlflite package in Flutter, and I have been reading a lot about it. However, everywhere I find the example being shown for the single model, that is

SingleModel{
  String data1, data2;

  ....
}

I have followed

these as well, but that did not quite resolve it. My main requirements is to work with the data like this:

user: {
  'id': unique_key,
  'name': 'abc',
  'courses': [
    { 'coursename': 'some_coursename'},
    { 'coursename': 'some_other_coursename'}
  ]
}

I have designed my model correctly,

UserModel Class

class UserModel{
  int id;
  String name;
  List<Course> _courses;

  UserModel.set(Map data){
    this.id = data['id'];
    this.name = data['name'];
    if(data['courses'] != null)
         this.courses = [data['courses']];
  }

  // append more courses
  void setMorCourses(Map course){
     // checking for duplicate errors
     if(!this.courses.contains(course['course']))
         this.courses.add(course['course'])
  }
}

Now, I am confused on how to use the Nested Model with sqlflite. I believe I need to work in the DatabaseHelper class.

Course Class

class CourseModel{
  String coursename;

  CourseModel.set(Map data){
    this.coursename = data['coursename'];
  }
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Alok
  • 8,452
  • 13
  • 55
  • 93

0 Answers0