这是indexloc提供的服务,不要输入任何密码
Skip to content

Actables function does not work with :as  #46

@Taeir

Description

@Taeir

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions