I'm trying to define a user's ability to access something based on a column on an associated model (so something like can :read, Step, 'steppable' => {published: true}
), the problem is that it's a polymorphic association so it can't find the steppable table because it doesn't exist.
I've got steps, and each step has a steppable (either a lecture, a quiz, or some other action). I need an activerecord query that will work. I've tried:
Step.includes(:steppable).where('steppable' => {published: true})
and
Step.joins(:steppable).where('steppable' => {published: true})
But both result in ActiveRecord::EagerLoadPolymorphicError: Can not eagerly load the polymorphic association :steppable
Models look like this:
class Step < ActiveRecord::Base
...
belongs_to :steppable, polymorphic: true, dependent: :destroy
...
end
and
class Lecture
...
has_one :step, as: :steppable, dependent: :destroy
...
end
Note: I'd like to be agnostic regarding the associated model, and in order for it to work for fetching records with CanCan, it has to be done using database columns (see github.com/ryanb/cancan/wiki/defining-abilities)
Step.includes(:steppable).all
, just to check? What does your models look like? We need more information... – TimeserverActiveRecord::EagerLoadPolymorphicError: Can not eagerly load the polymorphic association :steppable
error. I updated the question with info on the model. – Theurich