Why the sql? Just let ActiveRecord do it's thing - `@group.documents.destroy(document_ids) will delete the joins.