Rails - STI bug for ActiveRecord_Relation, works fine for a single record
james-em opened this issue · comments
james-em commented
Simple explanation of the bug
MyModelBase.all.decorate
=> Could not infer a decorator for MyModelBase. (Draper::UninferrableDecoratorError)
MyModelBase.all.first.decorate
=> #<MyModelSpecificDecorator:0x000000012116d470
Workaround
PS: Can cause some performance drawbacks in some cases
MyModelBase.all.map(&:decorate)
Expected behavior
MyModelBase.all.decorate
shouldn't raise an error.
Alexander Senko commented
The question is: What result do you expect? What class do you want it to be / what methods to have?
-
You may define basic
MyModelBasesDecorator < Draper::CollectionDecorator
. It may be empty, that will do. -
If you don't want to for some reason, you can use a basic collection decorator:
Draper::CollectionDecorator.decorate MyModelBase.all
explicitly. Every record will be decorated with a decorator matching its class as in case 1.