# Join different querys in the same object

**URL:** <https://www.ruby-forum.com/t/join-different-querys-in-the-same-object/149498>\
**Category:** Rails\
**Created:** [September 25, 2008, 1:42pm UTC](https://www.ruby-forum.com/t/join-different-querys-in-the-same-object/149498 "2008-09-25T13:42:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dazuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d6d6ee/32.png) [@dazuma](https://www.ruby-forum.com/u/dazuma)\
**Post date:** [September 25, 2008, 1:42pm UTC](https://www.ruby-forum.com/t/join-different-querys-in-the-same-object/149498/1 "2008-09-25T13:42:40Z")

</div>

Hi, I’m new in Ruby on Rails and I don’t know how can I achive  
something like this:

@switchs = Switch.find(:all)  
for switch in @switchs  
if current\_user.shifts.count(:all,:conditions=\>[“date = ? and  
shift = ?”,switch.destiny\_date, switch.destiny\_turn]) !=0  
@valid = switch  
@valid.merge(cambio)  
end  
end  
return @valid

Let me explain. I just want to put in the same @valid object, switchs  
that satisfy the “if” condition. So, I have to loop for every switch  
and just select those ones that satisfy the condition. Is there any  
way to achieve this???

Thanks in advance.
