{"action":"created","issue":{"url":"https://api.github.com/repos/Vincit/objection.js/issues/439","repository_url":"https://api.github.com/repos/Vincit/objection.js","labels_url":"https://api.github.com/repos/Vincit/objection.js/issues/439/labels{/name}","comments_url":"https://api.github.com/repos/Vincit/objection.js/issues/439/comments","events_url":"https://api.github.com/repos/Vincit/objection.js/issues/439/events","html_url":"https://github.com/Vincit/objection.js/issues/439","id":242016511,"number":439,"title":"joinEager doesn't work with table names that contain a postgresql schema","user":{"login":"pineapplemachine","id":7266412,"avatar_url":"https://avatars1.githubusercontent.com/u/7266412?v=3","gravatar_id":"","url":"https://api.github.com/users/pineapplemachine","html_url":"https://github.com/pineapplemachine","followers_url":"https://api.github.com/users/pineapplemachine/followers","following_url":"https://api.github.com/users/pineapplemachine/following{/other_user}","gists_url":"https://api.github.com/users/pineapplemachine/gists{/gist_id}","starred_url":"https://api.github.com/users/pineapplemachine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pineapplemachine/subscriptions","organizations_url":"https://api.github.com/users/pineapplemachine/orgs","repos_url":"https://api.github.com/users/pineapplemachine/repos","events_url":"https://api.github.com/users/pineapplemachine/events{/privacy}","received_events_url":"https://api.github.com/users/pineapplemachine/received_events","type":"User","site_admin":false},"labels":[{"id":199461320,"url":"https://api.github.com/repos/Vincit/objection.js/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":26,"created_at":"2017-07-11T11:35:01Z","updated_at":"2017-07-12T07:53:23Z","closed_at":null,"body":"I have a query that looks similar to this:\r\n\r\n``` js\r\nThing.query().first().select(\r\n    \"thingId\", \"creationTime\", \"author.emailAddress\"\r\n).joinRelation(\"author\" /* Join on users table */ ).where({\r\n    \"thingId\": thingId\r\n}).then(thing => doStuff(thing))\r\n```\r\n\r\nBoth the thing and user tables have a `creationTime` column. When I try to express the query like above I get an error `column reference \"creationTime\" is ambiguous`.\r\n\r\nOne solution would be to do this, but I really don't want to because it's verbose and repetitive and I'd have to do it in lots of places. It wouldn't help maintainability at all.\r\n\r\n``` js\r\nThing.query().first().select(\r\n    \"thingId\", \"thingSchemaName.thingTableName.creationTime\", \"author.emailAddress\"\r\n).joinRelation(\"author\" /* Join on users table */ ).where({\r\n    \"thingId\": thingId\r\n}).then(thing => doStuff(thing))\r\n```\r\n\r\nWhat I would very much like to do and would expect to be able to do - except I haven't worked out any way how - is to select the model table with an alias. Something nice and sensible and readable like\r\n\r\n\r\n``` js\r\nThing.query().as(\"thing\").first().select(\r\n    \"thing.thingId\", \"thing.creationTime\", \"author.emailAddress\"\r\n).joinRelation(\"author\" /* Join on users table */ ).where({\r\n    \"thing.thingId\": thingId\r\n}).then(thing => doStuff(thing))\r\n```\r\n\r\nOr, it would be quite nice if objection was able to automagically prepend the models' table name to selected columns that don't otherwise specify.\r\n\r\nWhat's the best way to fix this?"},"comment":{"url":"https://api.github.com/repos/Vincit/objection.js/issues/comments/314685124","html_url":"https://github.com/Vincit/objection.js/issues/439#issuecomment-314685124","issue_url":"https://api.github.com/repos/Vincit/objection.js/issues/439","id":314685124,"user":{"login":"pineapplemachine","id":7266412,"avatar_url":"https://avatars1.githubusercontent.com/u/7266412?v=3","gravatar_id":"","url":"https://api.github.com/users/pineapplemachine","html_url":"https://github.com/pineapplemachine","followers_url":"https://api.github.com/users/pineapplemachine/followers","following_url":"https://api.github.com/users/pineapplemachine/following{/other_user}","gists_url":"https://api.github.com/users/pineapplemachine/gists{/gist_id}","starred_url":"https://api.github.com/users/pineapplemachine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pineapplemachine/subscriptions","organizations_url":"https://api.github.com/users/pineapplemachine/orgs","repos_url":"https://api.github.com/users/pineapplemachine/repos","events_url":"https://api.github.com/users/pineapplemachine/events{/privacy}","received_events_url":"https://api.github.com/users/pineapplemachine/received_events","type":"User","site_admin":false},"created_at":"2017-07-12T07:53:23Z","updated_at":"2017-07-12T07:53:23Z","body":"Aha I believe I have what I need\r\n\r\n``` js\r\n        const query = app.db.Questionnaire.alias(\"questionnaire\").first().joinEager(\r\n            \"[author, title]\"\r\n        ).modifyEager(\"author\", qb => {\r\n            qb.select(\"emailAddress\");\r\n        }).select(\r\n            \"questionnaireId\", \"name\",\r\n            \"creationTime\", \"lastModifiedTime\"\r\n        ).where({\r\n            \"questionnaireId\": request.body.questionnaireId,\r\n            \"disabled\": false,\r\n        });\r\n```\r\n\r\nproduces\r\n\r\n``` text\r\n{ method: 'select',\r\n  options: {},\r\n  timeout: false,\r\n  cancelOnTimeout: false,\r\n  bindings: [ 4, false ],\r\n  __knexQueryUid: '535fb6f8-50ad-45df-8b88-872dda4bc068',\r\n  sql: 'select \"questionnaireId\", \"name\", \"creationTime\", \"lastModifiedTime\", \"author\".\"userId\" as \"author:userId\", \"author\".\"emailAddress\" as \"author:emailAddress\", \"title\".\"textId\" as \"title:textId\", \"title\".\"languageCode\" as \"title:languageCode\", \"title\".\"content\" as \"title:content\", \"title\".\"contentOrigin\" as \"title:contentOrigin\" from \"maptionnaire\".\"Questionnaires\" as \"questionnaire\" left join (select \"emailAddress\", \"userId\" from \"maptionnaire\".\"Users\") as \"author\" on \"author\".\"userId\" = \"questionnaire\".\"authorUserId\" left join \"maptionnaire\".\"MultilingualText\" as \"title\" on \"title\".\"textId\" = \"questionnaire\".\"titleTextId\" where \"questionnaireId\" = ? and \"disabled\" = ?' }\r\nQuestionnaire {\r\n  questionnaireId: 4,\r\n  name: 'New questionnaire',\r\n  creationTime: 2017-07-11T11:09:36.285Z,\r\n  lastModifiedTime: 2017-07-11T11:09:36.285Z,\r\n  author: User { emailAddress: 'cool@3cool.com' },\r\n  title: [] }\r\n```"}}
{"actor":{"display_login":"pineapplemachine"}}