Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Seriously, .or() always felt like a glaring omission.


I wrote it in SQL when I needed it, after all I knew SQL before AR came around. An OR is very rare and probably that's why it landed only in version 5.

Another implementation is Post.where(id: [1, 2]) which is SELECT * FROM posts WHERE id IN (1, 2). I guess a db would compile it into exactly the same code (dbs use different terms but that's what it is) but the performances could be different inside AR/Arel.


Post.find([1,2])

Works in Rails 4


It's not an omission per se, it's actually a challenging thing to implement. I'm sure they'd have done it sooner if it wasn't so hard to get right. Think of how the precedence rules would work: especially since the queries are composable, tacking on another .or() can do funny things semantically.


I think I chose my words poorly. I'm sure it was a huge undertaking, but the lack .or() is very noticeable in AR if you're coming from other ORMs or straight SQL.


I'm pretty sure that DHH strongly opposed .or(), but I'm not sure why. I'd really like to know if this is true, and if so, what the reasoning was.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: