# Rails3 Finders - OR conditions

**URL:** <https://www.ruby-forum.com/t/rails3-finders-or-conditions/192174>\
**Category:** Rails\
**Created:** [July 25, 2010, 6:21pm UTC](https://www.ruby-forum.com/t/rails3-finders-or-conditions/192174 "2010-07-25T18:21:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AppleII717](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@AppleII717](https://www.ruby-forum.com/u/AppleII717)\
**Post date:** [July 25, 2010, 6:21pm UTC](https://www.ruby-forum.com/t/rails3-finders-or-conditions/192174/1 "2010-07-25T18:21:43Z")

</div>

There just does not seem to be much information out their on Rails3  
finders.

The finders and chaining are basically “awesome”, at least if you are  
doing Model.where().where() which generates AND conditions. Can’t  
find much on OR condition examples, except putting the “or” conditions  
in text in the where arguments.

I think I read that OR was not working in arel yet, but I found  
something that I’m not sure if it’s rails3 or ruby that is making it  
work. Playing with a genealogy model  
Person:id,father\_id,mother\_id,name,etc. I wrote some model queries:

def parents  
Person.where(:id =\> [self.father\_id, self.mother\_id])  
end

def children  
self.gender == ‘m’ ? Person.where(:father\_id =\> self.id) :  
Person.where(:mother\_id =\> self.id)  
end

def siblings  
if self.father\_id \> 0 and self.mother\_id \> 0  
Person.where(:father\_id =\> self.father\_id, :mother\_id =\>  
self.mother\_id).where(“id != %d”,self.id)  
else  
[]  
end  
end

def half\_siblings  
fatherside = Person.where(:father\_id =\>  
self.father\_id).where(“mother\_id != ?”,self.mother\_id)  
motherside = Person.where(:mother\_id =\>  
self.mother\_id).where(“father\_id != ?”,self.father\_id)  
halfsiblings = fatherside | motherside  
end

The half\_siblings method requires an “or” condition and the “|”  
actually works but does not return a relation, but an array of AR’s.  
If I change the “|” to a “&”, which is an alias to merge and does the  
AND stuff and where I got the brainfart to try “|”, it returns a  
relation (that, of course fails to find any records).

Does anyone know of a good post on rails3 finders with some detailed  
examples?

Steve A.
