stffn/declarative_authorization — Issue #117: How to write this rule about tree structure
Author: lzpddd
Created: 2011-11-15 14:48:37+00:00
State: open

class User < ActiveRecord::Base
blongs_to	:organization
has_many :roles, :through => :assignments
...
def role_symbols
roles.map do |role|
role.name.underscore.to_sym
end
end
end

class Organization < ActiveRecord::Base
acts_as_tree
has_many :users
has_many :loans
end

organization have below records:
id	name	parent_id
1	organ1	null
2	organ2	1
3	organ2	2
4	organ2	2
5	organ2	3

class Loan < ActiveRecord::Base
belongs_to :organization
end

I want to list all records in Loan where ancestor is current_user.organization.id