{"action":"created","issue":{"url":"https://api.github.com/repos/composite-primary-keys/composite_primary_keys/issues/277","labels_url":"https://api.github.com/repos/composite-primary-keys/composite_primary_keys/issues/277/labels{/name}","comments_url":"https://api.github.com/repos/composite-primary-keys/composite_primary_keys/issues/277/comments","events_url":"https://api.github.com/repos/composite-primary-keys/composite_primary_keys/issues/277/events","html_url":"https://github.com/composite-primary-keys/composite_primary_keys/pull/277","id":54584640,"number":277,"title":"Fix habtm association #delete_records","user":{"login":"jurglic","id":112600,"avatar_url":"https://avatars.githubusercontent.com/u/112600?v=3","gravatar_id":"","url":"https://api.github.com/users/jurglic","html_url":"https://github.com/jurglic","followers_url":"https://api.github.com/users/jurglic/followers","following_url":"https://api.github.com/users/jurglic/following{/other_user}","gists_url":"https://api.github.com/users/jurglic/gists{/gist_id}","starred_url":"https://api.github.com/users/jurglic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jurglic/subscriptions","organizations_url":"https://api.github.com/users/jurglic/orgs","repos_url":"https://api.github.com/users/jurglic/repos","events_url":"https://api.github.com/users/jurglic/events{/privacy}","received_events_url":"https://api.github.com/users/jurglic/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-16T15:03:43Z","updated_at":"2015-01-24T23:20:38Z","closed_at":"2015-01-24T23:20:37Z","pull_request":{"url":"https://api.github.com/repos/composite-primary-keys/composite_primary_keys/pulls/277","html_url":"https://github.com/composite-primary-keys/composite_primary_keys/pull/277","diff_url":"https://github.com/composite-primary-keys/composite_primary_keys/pull/277.diff","patch_url":"https://github.com/composite-primary-keys/composite_primary_keys/pull/277.patch"},"body":"Fixes #273 - habtm association issue when destroying a record.\r\n\r\nLet say we have a Foo record that has-and-belongs-to-many Bar records. When we destroy Foo record, the association data in the junction table bars_foos doesn't get deleted. On closer inspection this happens because of the invalid delete statement which silently fails, e.g.:\r\n```\r\n  DELETE FROM `bars_foos` WHERE `bars_foos`.`foo_id` = 1 AND NULL\r\n```\r\n\r\nThis commit amends the habtm test to fail and demonstrate this bug.\r\n\r\nThen it addresses this bug inside the HasAndBelongsToManyAssociation in the #delete_records. It makes sure only non-empty predicates are used when scoping the to-be-removed records of the junction table.\r\n\r\nConsequently a valid delete statement is generated and test passes."},"comment":{"url":"https://api.github.com/repos/composite-primary-keys/composite_primary_keys/issues/comments/71342566","html_url":"https://github.com/composite-primary-keys/composite_primary_keys/pull/277#issuecomment-71342566","issue_url":"https://api.github.com/repos/composite-primary-keys/composite_primary_keys/issues/277","id":71342566,"user":{"login":"cfis","id":18630,"avatar_url":"https://avatars.githubusercontent.com/u/18630?v=3","gravatar_id":"","url":"https://api.github.com/users/cfis","html_url":"https://github.com/cfis","followers_url":"https://api.github.com/users/cfis/followers","following_url":"https://api.github.com/users/cfis/following{/other_user}","gists_url":"https://api.github.com/users/cfis/gists{/gist_id}","starred_url":"https://api.github.com/users/cfis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cfis/subscriptions","organizations_url":"https://api.github.com/users/cfis/orgs","repos_url":"https://api.github.com/users/cfis/repos","events_url":"https://api.github.com/users/cfis/events{/privacy}","received_events_url":"https://api.github.com/users/cfis/received_events","type":"User","site_admin":false},"created_at":"2015-01-24T23:20:38Z","updated_at":"2015-01-24T23:20:38Z","body":"Thanks!"}}