{"action":"opened","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/10315","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/10315/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/10315/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/10315/events","html_url":"https://github.com/sequelize/sequelize/issues/10315","id":395766167,"node_id":"MDU6SXNzdWUzOTU3NjYxNjc=","number":10315,"title":"Order by sequelize.fn for underscored columns and left joins","user":{"login":"pyephyomaung","id":1734954,"node_id":"MDQ6VXNlcjE3MzQ5NTQ=","avatar_url":"https://avatars1.githubusercontent.com/u/1734954?v=4","gravatar_id":"","url":"https://api.github.com/users/pyephyomaung","html_url":"https://github.com/pyephyomaung","followers_url":"https://api.github.com/users/pyephyomaung/followers","following_url":"https://api.github.com/users/pyephyomaung/following{/other_user}","gists_url":"https://api.github.com/users/pyephyomaung/gists{/gist_id}","starred_url":"https://api.github.com/users/pyephyomaung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pyephyomaung/subscriptions","organizations_url":"https://api.github.com/users/pyephyomaung/orgs","repos_url":"https://api.github.com/users/pyephyomaung/repos","events_url":"https://api.github.com/users/pyephyomaung/events{/privacy}","received_events_url":"https://api.github.com/users/pyephyomaung/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-01-03T23:54:22Z","updated_at":"2019-01-03T23:54:22Z","closed_at":null,"author_association":"NONE","body":"Hello, I have the models equivalent to the following\r\n```const TableA = sequelize.define('TableA', {id: Sequelize.UUID, somethingName: Sequelize.STRING}),\r\n      TableB = sequelize.define('TableB', {id: Sequelize.UUID, title: Sequelize.STRING});\r\nTableA.hasMany(TableB, {as: 'Bs'});\r\nTableA.addScope('includeB', {include: [{model: TableB}]});```\r\nThen I do, something like\r\n```return models.TableA.scope('includeB').findAll({\r\n  where: {\r\n    somethingName: {[Op.like]: '%bla%abcd%'}\r\n  },\r\n  limit: 20,\r\n  offset: 100,\r\n  order: [\r\n    [sequelize.fn('similarity', sequelize.col('somethingName'), 'bla'), 'DESC']\r\n  ]\r\n})```\r\nit generates the query like this:\r\n```SELECT \"TableA\".*\r\n    ,\"TableB\".\"title\" AS \"TableB.title\"\r\n  ,\"TableB\".\"id\" AS \"TableB.id\"\r\n  ,\"TableB\".\"table_a_id\" AS \"TableB.tableAId\"\r\nFROM (\r\n    SELECT \"TableA\".\"id\"\r\n    FROM \"table_as\" AS \"TableA\"\r\n    WHERE \"table_as\".\"something_name\" ILIKE '%bla%abcd%'\r\n    ORDER BY similarity(\"somethingName\", 'bla') DESC LIMIT 21 OFFSET 100\r\n    ) AS \"TableA\"\r\nLEFT JOIN \"table_bs\" AS \"TableB\" ON \"TableA\".\"id\" = \"TableB\".\"table_a_id\"\r\nORDER BY similarity(\"somethingName\", 'bla') DESC;```\r\nBecause we use underscored column names in postgres, the `ORDER BY` clause inside the subquery is not working."}}
{"actor":{"display_login":"pyephyomaung"}}