{"action":"created","issue":{"url":"https://api.github.com/repos/merit-gem/merit/issues/264","repository_url":"https://api.github.com/repos/merit-gem/merit","labels_url":"https://api.github.com/repos/merit-gem/merit/issues/264/labels{/name}","comments_url":"https://api.github.com/repos/merit-gem/merit/issues/264/comments","events_url":"https://api.github.com/repos/merit-gem/merit/issues/264/events","html_url":"https://github.com/merit-gem/merit/issues/264","id":185182577,"number":264,"title":"Removal of badges/points when using dependent => destroy in model","user":{"login":"olliekav","id":9005,"avatar_url":"https://avatars.githubusercontent.com/u/9005?v=3","gravatar_id":"","url":"https://api.github.com/users/olliekav","html_url":"https://github.com/olliekav","followers_url":"https://api.github.com/users/olliekav/followers","following_url":"https://api.github.com/users/olliekav/following{/other_user}","gists_url":"https://api.github.com/users/olliekav/gists{/gist_id}","starred_url":"https://api.github.com/users/olliekav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olliekav/subscriptions","organizations_url":"https://api.github.com/users/olliekav/orgs","repos_url":"https://api.github.com/users/olliekav/repos","events_url":"https://api.github.com/users/olliekav/events{/privacy}","received_events_url":"https://api.github.com/users/olliekav/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-25T17:28:45Z","updated_at":"2016-10-25T17:37:37Z","closed_at":null,"body":"I'm trying to remove points and badges from Users if they delete records, but I can't work out/understand why deleting associated records doesn't run the BadgeRules?\r\n\r\nSo say I have a badge rule like this...\r\n\r\n```*ruby\r\ngrant_on ['observations#create', 'observations#destroy'], badge_id: 1, temporary: true, to: :user do |observation|\r\n        count = observation.user.observations.count\r\n        count >= 1 && count < 10\r\nend\r\n```\r\n\r\nAn Observation belongs to a Location, and a User is able to delete a Location with all the Observations belonging to it, in the Location model this is set as `dependent => :destroy`. \r\n\r\nThis works fine if a user deletes an Observation, the badges and points are removed, but why are the badge rules not being met when a Location is deleted? Are the actions set above not called on an associated record? Do I have to duplicate all the rules for `['locations#destroy']`?"},"comment":{"url":"https://api.github.com/repos/merit-gem/merit/issues/comments/256105714","html_url":"https://github.com/merit-gem/merit/issues/264#issuecomment-256105714","issue_url":"https://api.github.com/repos/merit-gem/merit/issues/264","id":256105714,"user":{"login":"tute","id":54260,"avatar_url":"https://avatars.githubusercontent.com/u/54260?v=3","gravatar_id":"","url":"https://api.github.com/users/tute","html_url":"https://github.com/tute","followers_url":"https://api.github.com/users/tute/followers","following_url":"https://api.github.com/users/tute/following{/other_user}","gists_url":"https://api.github.com/users/tute/gists{/gist_id}","starred_url":"https://api.github.com/users/tute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tute/subscriptions","organizations_url":"https://api.github.com/users/tute/orgs","repos_url":"https://api.github.com/users/tute/repos","events_url":"https://api.github.com/users/tute/events{/privacy}","received_events_url":"https://api.github.com/users/tute/received_events","type":"User","site_admin":false},"created_at":"2016-10-25T17:37:36Z","updated_at":"2016-10-25T17:37:36Z","body":"I think you'd need to add a rule like:\r\n\r\n```ruby\r\ngrant_on 'locations#destroy', badge_id: 1, temporary: true, to: :user do |location|\r\n  count = location.user.observations.count\r\n  count >= 1 && count < 10\r\nend\r\n```"}}
{"actor":{"display_login":"tute"}}