{"action":"created","issue":{"url":"https://api.github.com/repos/UnionOfRAD/lithium/issues/635","repository_url":"https://api.github.com/repos/UnionOfRAD/lithium","labels_url":"https://api.github.com/repos/UnionOfRAD/lithium/issues/635/labels{/name}","comments_url":"https://api.github.com/repos/UnionOfRAD/lithium/issues/635/comments","events_url":"https://api.github.com/repos/UnionOfRAD/lithium/issues/635/events","html_url":"https://github.com/UnionOfRAD/lithium/issues/635","id":6796342,"number":635,"title":"Fields specified in relationships are ignored","user":{"login":"danives","id":1133125,"avatar_url":"https://avatars.githubusercontent.com/u/1133125?v=3","gravatar_id":"","url":"https://api.github.com/users/danives","html_url":"https://github.com/danives","followers_url":"https://api.github.com/users/danives/followers","following_url":"https://api.github.com/users/danives/following{/other_user}","gists_url":"https://api.github.com/users/danives/gists{/gist_id}","starred_url":"https://api.github.com/users/danives/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danives/subscriptions","organizations_url":"https://api.github.com/users/danives/orgs","repos_url":"https://api.github.com/users/danives/repos","events_url":"https://api.github.com/users/danives/events{/privacy}","received_events_url":"https://api.github.com/users/danives/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/UnionOfRAD/lithium/labels/enhancement","name":"enhancement","color":"0052cc"},{"url":"https://api.github.com/repos/UnionOfRAD/lithium/labels/verified","name":"verified","color":"ffffff"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2012-09-11T17:42:21Z","updated_at":"2016-06-17T15:28:27Z","closed_at":null,"body":"Hi,\n\nI am trying to get a count of a related table with my query - however I do not know the correct way to do this. I tried specifying the field manually in the find:: method, but that returns only the field. I then thought I should do it using the relationships and specify the field in the relationship. This is a link to the example code I used:\n\nhttp://pastium.org/view/06085ba7423faa13f5316cd8a1eb33f2\n\nHowever doing that, the 'fields' variable is ignored - as can be seen in the generated SQL. I tried recreating the SQL statement and adding the field in manually, but it seems lithium doesn't then know how to bind the data to a model:\n\nhttp://pastium.org/view/06085ba7423faa13f5316cd8a1eb133d\n\nIf someone is able to help me with how to get an associated tables count, that would be fantastic.\n\nThanks,\n\nDan"},"comment":{"url":"https://api.github.com/repos/UnionOfRAD/lithium/issues/comments/226800793","html_url":"https://github.com/UnionOfRAD/lithium/issues/635#issuecomment-226800793","issue_url":"https://api.github.com/repos/UnionOfRAD/lithium/issues/635","id":226800793,"user":{"login":"davidpersson","id":29702,"avatar_url":"https://avatars.githubusercontent.com/u/29702?v=3","gravatar_id":"","url":"https://api.github.com/users/davidpersson","html_url":"https://github.com/davidpersson","followers_url":"https://api.github.com/users/davidpersson/followers","following_url":"https://api.github.com/users/davidpersson/following{/other_user}","gists_url":"https://api.github.com/users/davidpersson/gists{/gist_id}","starred_url":"https://api.github.com/users/davidpersson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidpersson/subscriptions","organizations_url":"https://api.github.com/users/davidpersson/orgs","repos_url":"https://api.github.com/users/davidpersson/repos","events_url":"https://api.github.com/users/davidpersson/events{/privacy}","received_events_url":"https://api.github.com/users/davidpersson/received_events","type":"User","site_admin":false},"created_at":"2016-06-17T15:28:27Z","updated_at":"2016-06-17T15:28:27Z","body":"Given an invoice hasMany positions, this is how you can get the number of positions an invoice has as `'positions_count'` for each Invoice. `'group'` does the trick here.\r\n \r\n```\r\n        $results = Invoices::find('all', [\r\n            'fields' => [\r\n                'Invoices.number',\r\n                'COUNT(Positions.id) AS positions_count',\r\n            ],\r\n            'group' => ['Invoices.id'],\r\n            'with' => ['Positions']\r\n        ]);\r\n```\r\n"}}
{"actor":{"display_login":"davidpersson"}}