現在、state_last_updated_by_id
フィールドでモデルの状態を最後に更新したユーザーと、フィールドで状態が最後に更新された時刻を保存していstate_updated_at
ます。次に、次のようなメソッドを定義します。
def published_at
return unless state == 'published'
state_updated_at
end
def published_by
return unless state == 'published'
state_last_updated_by
end
def nominated_for_publishing_at
return unless state == 'under_review'
state_updated_at
end
def nominated_for_publishing_by
return unless state == 'under_review'
state_last_updated_by
end
これは明らかにスケーリングしません (そして、そもそも優れたアプローチではありません) - これを行う正しい方法は何ですか?