Sequel has a concept of dynamic eager loading associations. Not to be wordy, consider the following code example:
class Artist < Sequel::Model
one_to_many :songs
end
# somewhere in the controller
Artist.eager(songs: -> (ds) { current_user ? ds : ds.where(status: :published) })
The construction with block literally implements this logic: if use is not authenticated there should be visible only published songs, otherwise all songs are visible.
I don’t think it’s the same. CanCan defines a scope. But the suggestion is for having this thing for associations so that it works with eager loading.
That might work. But then it comes to the question: what if there is another association, e.g. “artist has many liked_songs” that needs eager loaded but doesn’t need that filter?