{"action":"created","issue":{"url":"https://api.github.com/repos/hayashima/kakurenbo-puti/issues/1","labels_url":"https://api.github.com/repos/hayashima/kakurenbo-puti/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/hayashima/kakurenbo-puti/issues/1/comments","events_url":"https://api.github.com/repos/hayashima/kakurenbo-puti/issues/1/events","html_url":"https://github.com/hayashima/kakurenbo-puti/issues/1","id":60322614,"number":1,"title":"rails3でのnot inのスコープを作りたい","user":{"login":"kazuhisa","id":370800,"avatar_url":"https://avatars.githubusercontent.com/u/370800?v=3","gravatar_id":"","url":"https://api.github.com/users/kazuhisa","html_url":"https://github.com/kazuhisa","followers_url":"https://api.github.com/users/kazuhisa/followers","following_url":"https://api.github.com/users/kazuhisa/following{/other_user}","gists_url":"https://api.github.com/users/kazuhisa/gists{/gist_id}","starred_url":"https://api.github.com/users/kazuhisa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kazuhisa/subscriptions","organizations_url":"https://api.github.com/users/kazuhisa/orgs","repos_url":"https://api.github.com/users/kazuhisa/repos","events_url":"https://api.github.com/users/kazuhisa/events{/privacy}","received_events_url":"https://api.github.com/users/kazuhisa/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hayashima/kakurenbo-puti/labels/help%20wanted","name":"help wanted","color":"159818"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-09T10:17:33Z","updated_at":"2015-03-09T15:43:45Z","closed_at":null,"body":"@MnrUchida \r\nSQLの魔術師にお聞きしたいことがあります。\r\nRails4用のkakurenbo-putiをRails3で動くように修正してるんだけど、scopeの設定がうまく書けずに困っています。\r\nhttps://github.com/hayashima/kakurenbo-puti/blob/rails3/lib/kakurenbo_puti/active_record_base.rb#L41-L56\r\n問題はここの`only_soft_destroyed`ってスコープを定義しているところです。\r\nActiveRecord4のmasterブランチで動かすとonly_soft_destroyedは次のようなSQLになります。\r\n```SQL\r\nSELECT \"soft_delete_children\".* FROM \"soft_delete_children\" WHERE (\"soft_delete_children\".\"id\" NOT IN (\r\nSELECT \"soft_delete_children\".\"id\" FROM \"soft_delete_children\" INNER JOIN \"soft_delete_models\" ON \"soft_delete_models\".\"id\" = \"soft_delete_children\".\"soft_delete_model_id\" INNER JOIN \"normal_models\" ON \"normal_models\".\"id\" = \"soft_delete_children\".\"normal_model_id\" WHERE \"soft_delete_children\".\"soft_destroyed_at\" IS NULL AND \"soft_delete_models\".\"soft_destroyed_at\" IS NULL))\r\n```\r\n\r\nActiveRecord3のrails3ブランチでも同様に`without_soft_destroyed.select(:id)`の結果をnot in idにうまく指定できればRails3でも動くと思っています。\r\nどうやって指定すればいいでしょうか？\r\n\r\n`bundle exec rspec`で動作検証はできると思うので、見てみてもらえないでしょうか？"},"comment":{"url":"https://api.github.com/repos/hayashima/kakurenbo-puti/issues/comments/77878611","html_url":"https://github.com/hayashima/kakurenbo-puti/issues/1#issuecomment-77878611","issue_url":"https://api.github.com/repos/hayashima/kakurenbo-puti/issues/1","id":77878611,"user":{"login":"kazuhisa","id":370800,"avatar_url":"https://avatars.githubusercontent.com/u/370800?v=3","gravatar_id":"","url":"https://api.github.com/users/kazuhisa","html_url":"https://github.com/kazuhisa","followers_url":"https://api.github.com/users/kazuhisa/followers","following_url":"https://api.github.com/users/kazuhisa/following{/other_user}","gists_url":"https://api.github.com/users/kazuhisa/gists{/gist_id}","starred_url":"https://api.github.com/users/kazuhisa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kazuhisa/subscriptions","organizations_url":"https://api.github.com/users/kazuhisa/orgs","repos_url":"https://api.github.com/users/kazuhisa/repos","events_url":"https://api.github.com/users/kazuhisa/events{/privacy}","received_events_url":"https://api.github.com/users/kazuhisa/received_events","type":"User","site_admin":false},"created_at":"2015-03-09T15:43:45Z","updated_at":"2015-03-09T15:43:45Z","body":"@MnrUchida \r\n素晴らしい！僕もArelを使うパターンと似たようなことを試行錯誤してたんだけど、結局良く分からなかった...\r\nありがとう！"}}