Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
orderするとwhereで絞り込んだレコードが復活しちゃう
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
You can’t perform that action at this time.