Last active
August 29, 2015 14:11
-
-
Save nyaahara/bf2084ec2e7b5432d0fa to your computer and use it in GitHub Desktop.
orderするとwhereで絞り込んだレコードが復活しちゃう
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hoge < ActiveRecord::Base | |
has_many :fugas | |
end | |
class Fuga < ActiveRecord::Base | |
belongs_to :hoge | |
end | |
# statusがnullのレコードだけが取得 | |
Hoge.all.includes(:fugas).references(:fugas).where('fugas.status is null').first.fugas | |
# statusがnull以外のレコードも取得 | |
Hoge.all.includes(:fugas).references(:fugas).where('fugas.status is null').first.fugas.order(:id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment