
How does ActiveRecord#find work? - myShoggoth
https://www.omniref.com/ruby/gems/activerecord/4.2.0/symbols/ActiveRecord::Core::ClassMethods/find?#annotation=4071448&line=126
======
timr
Hi, author of the post here -- I actually skipped a few steps in this code,
because it was getting quite long. As it turns out, ActiveRecord is amazingly
complicated, even for the simplest of queries.

It's trying to build an AST for every query, and that AST uses Arel, which is
its own, complex layer of abstraction. There are a lot of layers of turtles
before you get to anything that looks like SQL.

~~~
sanderjd
Awhile ago I found a patch to Arel fixing up its support of unions, which I
wanted to use, but it hadn't been merged and had fallen behind the version I
was on. Fixing it up for the newer version required enough tweaking that I had
to actually figure out how the code worked. I found it to be an impressively
simple and well-written solution to an inherently complex problem.

All of this is to say that it would be neat to see this journey go even
deeper!

~~~
timr
Into Arel, you mean? Happy to do that. It would be a good opportunity to
really understand that code better!

~~~
sanderjd
Yeah that's what I meant!

------
aturek
Here's an optimization that one of the maintainers of rails is doing (has
already done?) on #find

[http://tenderlovemaking.com/2014/02/19/adequaterecord-pro-
li...](http://tenderlovemaking.com/2014/02/19/adequaterecord-pro-like-
activerecord.html)

~~~
weaksauce
that was added as art of rails 4.2.0

~~~
weaksauce
My keyboard seems to disregard about 25% of all my p, k, and l key presses.
The above should have been part. I'd throw the keyboard out but I love the
layout of it. If anyone knows of a Microsoft natural Internet keyboard layout
with mechanical switches I'd buy a few immediately. There's got to be a
bespoke keyboard business out there somewhere with all the 3d printers
nowadays.

------
jerhinesmith
I really appreciate what the omniref guys are doing, but I find these "posts"
(maybe not the right word?) incredibly difficult to follow. I can't tell if
I'm supposed to read the left pane, the right pane, the bubble? Do I click the
quote bubbles? Does the left pane "track" the right pane?

~~~
timr
In this case, the "bubble" is the thing...but yeah, it's a little noisy.
Perhaps if we fuzzed out the background a bit when the annotation viewer (the
bubble) is open it would help?

~~~
simoncion
Please don't do this. It was immediately obvious to me which part was the part
I was supposed to read. (And I've never visited this site before today!)

~~~
timr
Hah...we'll put it in the "maybe" folder for now.

------
reledi
That was a neat investigation and use of omniref.

I just posted a question:
[https://www.omniref.com/ruby/gems/activerecord/4.2.0/symbols...](https://www.omniref.com/ruby/gems/activerecord/4.2.0/symbols/ActiveRecord::Persistence/delete?#annotation=4079388)

I see that it popped up under recent questions on the home page. Once a
question gets bumped off that list, is there an easy way to find it (e.g.
through search) or can one only find it if they happen to be viewing the Q&A
tab under the same file?

Since this is my first question there, I'm not sure if I have to check back
repeatedly for answers or if I'll get notified somehow.

------
lygaret
I love these, great work. One minor nitpick; the next/previous links seem like
they're backwards: I ended up hitting previous by mistake twice, thinking I
was moving forwards.

~~~
timr
Because the links are actually wrong, or because they're in a confusing order?
If they're wrong somewhere, definitely let me know!

------
jordanpg
Is there an Omniref equivalent for Java?

~~~
timr
There will be...as soon as we build it. ;-)

(seriously, though: vote registered for Java as our next language.)

~~~
jim_greco
I'll second that vote. Very cool stuff guys.

