Skip to content

resourcifying an STI table at the base class level #376

Description

@AlexeyMK

My application has Users and many kinds of Applications (with STI). Users can have roles on Applications. I was hoping to use STI with resourcify, only applying resourcify on the base Application class.

Currently, if I add resourcify to the base class, the Role gets created, but when I try User.first.roles, the ApplicationSubType resources aren't found.

For now, I'm just going to add resourcify to every Application sub-type, and it's fine. However, it would be nice to have more native support from Resourcify.

Looking at https://github.com/RolifyCommunity/rolify/blob/99d886e8c5ba2f554f1c3573fcd91575a16dd3e5/lib/rolify.rb,

  def resourcify(association_name = :roles, options = {})
    include Resource

    options.reverse_merge!({ :role_cname => 'Role', :dependent => :destroy })
    resourcify_options = { :class_name => options[:role_cname].camelize, :as => :resource, :dependent => options[:dependent] }
    self.role_cname = options[:role_cname]
    self.role_table_name = self.role_cname.tableize.gsub(/\//, "_")

    has_many association_name, resourcify_options

    self.resource_adapter = Rolify::Adapter::Base.create("resource_adapter", self.role_cname, self.name)
    @@resource_types << self.name
  end

it seems like simply allowing an option to override self.name to always use Application as the resource name would be a simple-enough fix; that said, I haven't looked into the issue deeply.

Let me know if this seems at all feasible - happy to send in a PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions