{"action":"closed","issue":{"url":"https://api.github.com/repos/getquill/quill/issues/463","repository_url":"https://api.github.com/repos/getquill/quill","labels_url":"https://api.github.com/repos/getquill/quill/issues/463/labels{/name}","comments_url":"https://api.github.com/repos/getquill/quill/issues/463/comments","events_url":"https://api.github.com/repos/getquill/quill/issues/463/events","html_url":"https://github.com/getquill/quill/issues/463","id":166881443,"number":463,"title":"for-comprehension generates query with table name duplicates in both FROM and (LEFT) JOIN clauses.","user":{"login":"mxl","id":1078685,"avatar_url":"https://avatars.githubusercontent.com/u/1078685?v=3","gravatar_id":"","url":"https://api.github.com/users/mxl","html_url":"https://github.com/mxl","followers_url":"https://api.github.com/users/mxl/followers","following_url":"https://api.github.com/users/mxl/following{/other_user}","gists_url":"https://api.github.com/users/mxl/gists{/gist_id}","starred_url":"https://api.github.com/users/mxl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mxl/subscriptions","organizations_url":"https://api.github.com/users/mxl/orgs","repos_url":"https://api.github.com/users/mxl/repos","events_url":"https://api.github.com/users/mxl/events{/privacy}","received_events_url":"https://api.github.com/users/mxl/received_events","type":"User","site_admin":false},"labels":[{"id":238522442,"url":"https://api.github.com/repos/getquill/quill/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-07-21T18:03:25Z","updated_at":"2016-11-02T03:18:21Z","closed_at":"2016-11-02T03:18:21Z","body":"**Version**: `0.8.1-SNAPSHOT`\n**Module**: `quill-async`\n### Expected behavior\n\nExpected to generate query:\n\n```\nSELECT e1.id, x1.id \nFROM first_entity e1\nLEFT JOIN second_entity x1 ON x1.id = e1.id\n```\n### Actual behavior\n\nGenerated query has duplicate table name in FROM clause:\n\n```\nSELECT e1.id, x1.id \nFROM first_entity e1, second_entity x1 \nLEFT JOIN second_entity x1 ON x1.id = e1.id\n\n```\n### Steps to reproduce the behavior\n\n```\nimport io.getquill.{PostgresAsyncContext, SnakeCase}\nimport scala.concurrent.ExecutionContext.Implicits.global\n\ncase class FirstEntity(id: Int)\n\ncase class SecondEntity(id: Int)\n\nobject Main extends App {\n  val context = new PostgresAsyncContext[SnakeCase](\"database\")\n\n  import context._\n\n  context.run(quote(\n    for {\n      e1 <- query[FirstEntity]\n      e2 <- query[SecondEntity].leftJoin(_.id == e1.id)\n    } yield (e1.id, e2.map(_.id))\n  ))\n}\n```\n### Workaround\n\n```\ncontext.run(quote(\n  for {\n    (e1, e2) <- query[FirstEntity].leftJoin(query[SecondEntity]).on((t1, t2) => t1.id == t2.id)\n  } yield (e1.id, e2.map(_.id))\n))\n```\n\ngenerates:\n\n```\n SELECT t1.id, t2.id FROM first_entity t1 LEFT JOIN second_entity t2 ON t1.id = t2.id\n```\n### P. S.\n\nI tried example from documentation:\n\n```\nimport io.getquill.{PostgresAsyncContext, SnakeCase}\nimport scala.concurrent.ExecutionContext.Implicits.global\n\ncase class Person(id: Int, name: String, age: Int)\ncase class Contact(personId: Int, phone: String)\ncase class Employer(id: Int, personId: Int, name: String)\n\nobject Main extends App {\n  val context = new PostgresAsyncContext[SnakeCase](\"database\")\n\n  import context._\n\n  context.run(quote {\n    for{\n      (p,e) <- query[Person].join(query[Employer]).on(_.id == _.personId)\n      c  <- query[Contact].leftJoin(_.personId == p.id)\n    } yield(p, e, c)\n  })\n}\n```\n\nand it generates valid query:\n\n```\nSELECT x1.id, x1.name, x1.age, x2.id, x2.person_id, x2.name, x3.person_id, x3.phone \nFROM person x1 \nINNER JOIN employer x2 ON x1.id = x2.person_id \nLEFT JOIN contact x3 ON x3.person_id = x1.id\n```\n\nbut if I remove join with Employer table:\n\n```\nimport io.getquill.{PostgresAsyncContext, SnakeCase}\nimport scala.concurrent.ExecutionContext.Implicits.global\n\ncase class Person(id: Int, name: String, age: Int)\ncase class Contact(personId: Int, phone: String)\ncase class Employer(id: Int, personId: Int, name: String)\n\nobject Main extends App {\n  val context = new PostgresAsyncContext[SnakeCase](\"database\")\n\n  import context._\n\n  context.run(quote {\n    for{\n      p <- query[Person]\n      c  <- query[Contact].leftJoin(_.personId == p.id)\n    } yield(p, c)\n  })\n}\n```\n\nthen it also generates invalid query with duplicate table name:\n\n```\nSELECT p.id, p.name, p.age, x1.person_id, x1.phone \nFROM person p, contact x1 \nLEFT JOIN contact x1 ON x1.person_id = p.id\n```\n\n@getquill/maintainers\n"}}
{"actor":{"display_login":"fwbrasil"}}