-
Notifications
You must be signed in to change notification settings - Fork 4
Description
The relation method actables
(ActsAs::ReflectionsWithActsAs) is not documented in the README (I was about to propose a feature request for this functionality 😅, I've added a small PR to add it in there).
That aside, actables
seems to only work when the default name of actable
is used (it uses hardcoded where(actable_id: ...)
).
So a configuration like
class Product < ActiveRecord::Base
actable as: :producible
end
class Pen < ActiveRecord::Base
acts_as :product, as: :producible
end
Product.where(price: 0.8).actables
will not work.
I believe to make actables
work with differently named relations, the ActsAs::Relations::ClassMethods
needs to define a way to retrieve the as
parameter, or pass it along somehow. It would also need to define a method on the class instance with the plural of what is passed to the as
. Something along the lines of:
...
singleton_class.module_eval do
include ActsAs::ClassMethods
def <as.to_s.pluralize.to_sym>
acting_as_model.where("#{as}_id" => select(:id))
end
end
I'm afraid I do not quite know how to do that, or I would suggest a pull request myself. However, perhaps it is possible for you to add this?