Fetching data from multiple tables not mapping data in auto-generated class #664
Unanswered
neeluagrawal04
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have 3 rows in 1st table and 2 rows in
https://github.com/entity Admin> id, userId, adminName
https://github.com/entity User> userId, userName
Now I want to fetch all the data from Admin and user table when userId of Admin table matches with userId of User table.
Result after executing query is list: id, userId, adminName, userName
So my table structure will be like:
https://github.com/entity(
tableName: 'Admin',
primaryKeys: ['id', 'userId'])
class Admin {
@ColumnInfo(name: 'id')
final String id;
@ColumnInfo(name: 'userId')
final String? userId;
@ColumnInfo(name: 'adminName')
final String adminName;
@ignore
String? userName; // since i don't want to include it as table row
Admin(
{required this.id,
this.adminName,
required this.userId,
this.userName});
}
https://github.com/entity(
tableName: 'User',
primaryKeys: ['id'])
class User {
@ColumnInfo(name: 'userId')
final String userId;
@ColumnInfo(name: 'userName')
final String? userName;
User(
{required this.userId,
this.userName});
}
so after writing the query in dao class
@query('SELECT *, User.userName FROM Admin, User where Admin.userId = User.userId ')
Future getAdminUserData();
on running the command to update the auto-generated file
:: flutter pub run build_runner build --delete-conflicting-outputs
the function
@OverRide
Future getAdminUserData() async {
return _queryAdapter.queryList(
'SELECT *, Admin.id, Admin.adminName, Admin.userId, Admin.userName FROM Admin, User WHERE Admin.userid = User.Admin',
mapper: (Map<String, Object?> row) => Admin(id: row['id'] as String, adminName: row['adminName'] as String?, userId: row['userId'] as String?));
}
so in above function userName i am not able to see. This is the issue
Please let me know whats wrong I am doing into this
Beta Was this translation helpful? Give feedback.
All reactions