tekartik / sqflite

SQLite flutter plugin
BSD 2-Clause "Simplified" License
2.86k stars 521 forks source link

One to many relationship using SQFlite #394

Open Dying5566 opened 4 years ago

Dying5566 commented 4 years ago

I was hoping someone could write or show me an example of a "One to Many" relationship in Flutter using SQFlite.

luisEnriqueR commented 4 years ago

One to many is when you have a relation between a table that contains a primary key that will identify that certain element giving the option to have multiple relationships with other elements in certain column. you can see an example right here teachers: teacher_id, first_name, last_name # the "one" side classes: class_id, class_name, teacher_id # the "many" side

then the foreign key is the way to match the multiple rows in the classes table to a certain teacher you create the two tables using the documentation with this and you only need to follow this logic, it's basically like normal sql for the most of the cases... just differentiate in certain data types.