title: Chain has_many :through associations
body: <p>I would like to know if there is a more elegant way to chain has_many through relationships. In my example I have a user whom can have multiple roles. Each role has multiple permissions. So a user has multiple permissions. The code below works fine, but I am wonder if there is a better way to do this. </p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :role_user_mappings
    has_many :roles, through: :role_user_mappings
  
    def permissions
      permitted_actions = []
      self.roles.each do |role|
         role.permissions.each do |permission|
           permitted_actions &lt;&lt; permission
         end
      end
      permitted_actions
    end
  end
  
  class Role &lt; ActiveRecord::Base
    has_many :permission_role_mappings
    has_many :permissions, through: :permission_role_mappings
  end
  
  class Permission &lt; ActiveRecord::Base
  end
  
  class PermissionRoleMapping &lt; ActiveRecord::Base
    belongs_to :permission
    belongs_to :role
  end
  
  class RoleUserMapping &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :role
  end
  </code></pre>
  
  <p>I would like to be able to do this. </p>
  
  <pre><code>user.permissions
  </code></pre>
  
  <p><strong>EDIT: Tried</strong>
  On thing that I tried that at least DRYs the User model a little bit is adding the function as a concern</p>
  
  <pre><code>module Permittable
    extend ActiveSupport::Concern
  
    def permissions
      permitted_actions = []
      self.roles.each do |role|
         role.permissions.each do |permission|
           permitted_actions &lt;&lt; permission
         end
      end
      permitted_actions
    end
  end
  </code></pre>