# Some logic problem

**URL:** <https://www.ruby-forum.com/t/some-logic-problem/185397>\
**Category:** Rails\
**Created:** [March 19, 2010, 7:03am UTC](https://www.ruby-forum.com/t/some-logic-problem/185397 "2010-03-19T07:03:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [March 19, 2010, 7:03am UTC](https://www.ruby-forum.com/t/some-logic-problem/185397/1 "2010-03-19T07:03:28Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [March 19, 2010, 7:28am UTC](https://www.ruby-forum.com/t/some-logic-problem/185397/2 "2010-03-19T07:28:11Z")

</div>

On Fri, Mar 19, 2010 at 12:03 AM, Hemant B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> ```
> EmployeeF
> 
> ```
> 
> end  
> You received this message because you are subscribed to the Google G.  
> “Ruby on Rails: Talk” group.  
> To post to this group, send email to removed\_email\_address@domain.invalid.  
> To unsubscribe from this group, send email to  
> removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> .  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

Perhaps you have a loop.

EmployeeX manages EmployeeY and EmployeeY manages EmployeeX

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [March 19, 2010, 7:39am UTC](https://www.ruby-forum.com/t/some-logic-problem/185397/3 "2010-03-19T07:39:36Z")

</div>

Hi josh,

Thanks for a quickie, But how to get rid of this loop …

Josh C. wrote:

> Perhaps you have a loop.
> 
> EmployeeX manages EmployeeY and EmployeeY manages EmployeeX

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [March 19, 2010, 9:39am UTC](https://www.ruby-forum.com/t/some-logic-problem/185397/4 "2010-03-19T09:39:52Z")

</div>

On 19 March 2010 06:39, Hemant B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi josh,
> 
> Thanks for a quickie, But how to get rid of this loop …
> 
> Josh C. wrote:
> 
> > Perhaps you have a loop.
> > 
> > EmployeeX manages EmployeeY and EmployeeY manages EmployeeX

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

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [March 19, 2010, 10:06am UTC](https://www.ruby-forum.com/t/some-logic-problem/185397/5 "2010-03-19T10:06:30Z")

</div>

Thanks colin.

Resolved it as well. Cheers … !!

Colin L. 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
