node-sql-query icon indicating copy to clipboard operation
node-sql-query copied to clipboard

Problem mapping field on use Join

Open icharge opened this issue 7 years ago • 0 comments

const sql = sqlQuery.select()
      .from('machine_log')
      .select('when', 'machine_id', 'event')
      .from('machines', 'machine_id ', 'machine_log', 'machine_id')
      .select('name')
      .order('when', 'Z')
      .limit(limit)
      .build();

And it produce this SQL that so wrong

SELECT `t1`.`when`, `t1`.`machine_id`, `t1`.`event`, `t2`.`name` FROM `machine_log` `t1` JOIN `machines` `t2` ON `t2`.`machines` = `t1`.`machine_id` ORDER BY `when` DESC LIMIT 10

ON t2.machines must be ON t2.machine_id like this

SELECT `t1`.`when`, `t1`.`machine_id`, `t1`.`event`, `t2`.`name` FROM `machine_log` `t1` JOIN `machines` `t2` ON `t2`.`machine_id` = `t1`.`machine_id` ORDER BY `when` DESC LIMIT 10

icharge avatar Oct 15 '18 17:10 icharge