Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mappedResultsQuery should be mapped to table Alias instead table Name #137

Open
supermuka opened this issue Jun 30, 2020 · 2 comments
Open

Comments

@supermuka
Copy link

supermuka commented Jun 30, 2020

mappedResultsQuery should be mapped to table Alias instead table Name, when has an alias.

Now, this works. But it ignores the alias on the table:

List<Map<String, Map<String, dynamic>>> results = await connection.mappedResultsQuery(
  "SELECT t_alias.id, t_alias.name, u_alias.name FROM t t_alias
   LEFT OUTER JOIN u u_alias ON t.id=u.t_id");

for (final row in results) {
  var tID = row["t"]["id"];
  var tName = row["t"]["name"];
  var uName = row["u"]["name"];
}

But the correct way should be with alias:

for (final row in results) {
  var tID = row["t_alias"]["id"];
  var tName = row["t_alias"]["name"];
  var uName = row["u_alias"]["name"];
}

Column name x alias is working correctly. When it has an alias in column, the mappedResultsQuery returns the alias instead column name.

@supermuka supermuka changed the title mappedResultsQuery map table Alias instead table Name mappedResultsQuery should be mapped to table Alias instead table Name Jun 30, 2020
@isoos
Copy link
Collaborator

isoos commented Jun 30, 2020

Hm, this is especially true if the same table is joined with two alias.

@supermuka
Copy link
Author

Yes, exactly!

With this query we have problems. But it should work correctly with results below:

List<Map<String, Map<String, dynamic>>> results = await connection.mappedResultsQuery(
  "SELECT t_alias.id, t_alias.name, u_alias.name, u_two_alias.name FROM t t_alias
   LEFT OUTER JOIN u u_alias ON t_alias.id=u_alias.t_id
   LEFT OUTER JOIN u u_two_alias ON t_alias.id_two=u_tow_alias.t_id");


for (final row in results) {
  var tID = row["t_alias"]["id"];
  var tName = row["t_alias"]["name"];
  var uName = row["u_alias"]["name"];
  var uTwoName = row["u_two_alias"]["name"];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants