{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/5006","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/5006/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/5006/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/5006/events","html_url":"https://github.com/sequelize/sequelize/issues/5006","id":121199486,"number":5006,"title":"Different parsing using aggregate function","user":{"login":"mazzy89","id":5463218,"avatar_url":"https://avatars.githubusercontent.com/u/5463218?v=3","gravatar_id":"","url":"https://api.github.com/users/mazzy89","html_url":"https://github.com/mazzy89","followers_url":"https://api.github.com/users/mazzy89/followers","following_url":"https://api.github.com/users/mazzy89/following{/other_user}","gists_url":"https://api.github.com/users/mazzy89/gists{/gist_id}","starred_url":"https://api.github.com/users/mazzy89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mazzy89/subscriptions","organizations_url":"https://api.github.com/users/mazzy89/orgs","repos_url":"https://api.github.com/users/mazzy89/repos","events_url":"https://api.github.com/users/mazzy89/events{/privacy}","received_events_url":"https://api.github.com/users/mazzy89/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-12-09T09:59:45Z","updated_at":"2015-12-09T12:41:09Z","closed_at":null,"body":"This is the query I've written:\r\n\r\n```\r\n    return db.Investment.findAll({\r\n        attributes: [\r\n          'id',\r\n          'primaryAccountId'\r\n        ],\r\n        where: {\r\n          primaryAccountId: accountId\r\n        },\r\n        include: [\r\n          { model: db.Transaction,\r\n            as: 'transactions',\r\n            attributes: [\r\n              [ db.sequelize.fn('SUM', db.sequelize.col('dollars')), 'totalValue' ],\r\n              [ db.sequelize.fn('SUM', db.sequelize.col('shares')), 'totalShares' ]\r\n            ],\r\n          }\r\n        ],\r\n        group: ['Investment.id']\r\n      }).then((result) => result);\r\n```\r\n\r\nAnd this is how the query it is parsed...\r\n\r\n```\r\nSELECT \"Investment\".\"id\", \"Investment\".\"primary_account_id\" AS \"primaryAccountId\", \"transactions\".\"id\" AS \"transactions.id\", SUM(\"dollars\") AS \"transactions.totalValue\", SUM(\"shares\") AS \"transactions.totalShares\" \r\nFROM \"Investments\" AS \"Investment\" LEFT OUTER JOIN \"Transactions\" AS \"transactions\" ON \"Investment\".\"id\" = \"transactions\".\"investment_id\" \r\nWHERE \"Investment\".\"primary_account_id\" = '1' \r\nGROUP BY \"Investment\".\"id\";\r\n```\r\n\r\nUnfortunately it doesn't work...the right way it should be the following:\r\n\r\n```\r\nSELECT \"Investment\".\"id\", \"Investment\".\"primary_account_id\" AS \"primaryAccountId\", SUM(\"dollars\") AS \"transactions.totalValue\", SUM(\"shares\") AS \"transactions.totalShares\" \r\nFROM \"Investments\" AS \"Investment\" LEFT OUTER JOIN \"Transactions\" AS \"transactions\" ON \"Investment\".\"id\" = \"transactions\".\"investment_id\" \r\nWHERE \"Investment\".\"primary_account_id\" = '1' \r\nGROUP BY \"Investment\".\"id\";\r\n```\r\n\r\nCan you recommend a way to fix this?\r\n"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/163214672","html_url":"https://github.com/sequelize/sequelize/issues/5006#issuecomment-163214672","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/5006","id":163214672,"user":{"login":"mickhansen","id":699049,"avatar_url":"https://avatars.githubusercontent.com/u/699049?v=3","gravatar_id":"","url":"https://api.github.com/users/mickhansen","html_url":"https://github.com/mickhansen","followers_url":"https://api.github.com/users/mickhansen/followers","following_url":"https://api.github.com/users/mickhansen/following{/other_user}","gists_url":"https://api.github.com/users/mickhansen/gists{/gist_id}","starred_url":"https://api.github.com/users/mickhansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mickhansen/subscriptions","organizations_url":"https://api.github.com/users/mickhansen/orgs","repos_url":"https://api.github.com/users/mickhansen/repos","events_url":"https://api.github.com/users/mickhansen/events{/privacy}","received_events_url":"https://api.github.com/users/mickhansen/received_events","type":"User","site_admin":false},"created_at":"2015-12-09T12:41:09Z","updated_at":"2015-12-09T12:41:09Z","body":"Well you don't need a completely raw query, but you can add `raw: true` to your find options, that should help."}}