postgresql-dart icon indicating copy to clipboard operation
postgresql-dart copied to clipboard

mappedResultsQuery should be mapped to table Alias instead table Name

Open supermuka opened this issue 5 years ago • 2 comments

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 avatar Jun 30 '20 14:06 supermuka

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

isoos avatar Jun 30 '20 15:06 isoos

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"];
}

supermuka avatar Jul 02 '20 17:07 supermuka