There just does not seem to be much information out their on Rails3
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:
Person.where(:id => [self.father_id, self.mother_id])
self.gender == 'm' ? Person.where(:father_id => self.id) :
Person.where(:mother_id => self.id)
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)
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
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