例えばapplication_rbで以下のようにscopeを定義した場合
class ApplicationRecord < ActiveRecord::Base self.abstract_class = true scope :relate, -> { includes(:users).includes(:items) } end
userやitemのほかに例えばmessageというmodelクラスがある場合(userとitemにはリレーションが張られているとします)に
modelクラスはapplication_recordを継承しているので
@message = Message.relate
という形でscopeを使えますか?
ちょっとrubyの実行環境が無いため確認できていないのですがいかがでしょうか?
よろしくお願い致します。
あなたの回答
tips
プレビュー