5 ms·
Seriously, .or() always felt like a glaring omission.
by ch4s3 10y ago
Seriously, .or() always felt like a glaring omission.
- gleenn 10y agoIt'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.
- ch4s3 10y agoI 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.
- pmontra 10y agoI 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.
- chippy 10y agoPost.find([1,2]) Works in Rails 4
- dogweather 10y agoI'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.