Hello champs,
I am in dilemma here. I have structure like this:-
EmployeeA
|
EmployeeB EmployeeC EmployeeD
| |
EmployeeE EmployeeH
|
EmployeeF
Currently if i login with EmployeeA account, It shows me its direct
reports. Like wise if i''ll login with EmployeeD then it''ll
show me only
EmployeeH. If i''ll login with EmployeeB account then it''ll
only show me
EmployeeE.
But i want it like this:-
If i''ll login with EmployeeA, it should show me all.
If i''ll login with EmployeeB, it should show me E & F.
Currently i am trying it like this:-
def get_all_reports(employee)
direct_reports = employee.managed_employees
@all_reports += direct_reports
direct_reports.each do |report|
get_all_reports(report)
end
@all_reports
end
My logic is fine, i think but do not know where i am doing mistake ..
The error coming out is stack level too deep..
I hope you people got me right and help me for sure..
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Mar 19, 2010 at 12:03 AM, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Hello champs, > > I am in dilemma here. I have structure like this:- > > EmployeeA > | > EmployeeB EmployeeC EmployeeD > | | > EmployeeE EmployeeH > | > EmployeeF > > Currently if i login with EmployeeA account, It shows me its direct > reports. Like wise if i''ll login with EmployeeD then it''ll show me only > EmployeeH. If i''ll login with EmployeeB account then it''ll only show me > EmployeeE. > > But i want it like this:- > > If i''ll login with EmployeeA, it should show me all. > If i''ll login with EmployeeB, it should show me E & F. > > > Currently i am trying it like this:- > > def get_all_reports(employee) > direct_reports = employee.managed_employees > @all_reports += direct_reports > direct_reports.each do |report| > get_all_reports(report) > end > @all_reports > end > > > My logic is fine, i think but do not know where i am doing mistake .. > The error coming out is stack level too deep.. > > I hope you people got me right and help me for sure.. > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >Perhaps you have a loop. EmployeeX manages EmployeeY and EmployeeY manages EmployeeX -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi josh, Thanks for a quickie, But how to get rid of this loop .. Josh Cheek wrote:> Perhaps you have a loop. > > EmployeeX manages EmployeeY and EmployeeY manages EmployeeX-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 19 March 2010 06:39, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi josh, > > Thanks for a quickie, But how to get rid of this loop .. > > Josh Cheek wrote: > >> Perhaps you have a loop. >> >> EmployeeX manages EmployeeY and EmployeeY manages EmployeeXRemove it from the database and put in validations to stop it happening again. The infinite recursion could also be caused by an employee managing himself. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks colin. Resolved it as well. Cheers .. !! Colin Law wrote:> Remove it from the database and put in validations to stop it happening > again. > The infinite recursion could also be caused by an employee managing > himself. > > Colin-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.