Let's talk about this. "query1" will find tracks where the bpm is greater than 100, and it selects the "id" and "title". "query2" uses a fancy "with" clause (aka "common table expression") to find all tracks that have "Irish" in the description. It joins this with tracks and selects only the "id", "title", and "description" fields.
So, what happens if I merge them? Exactly what should happen:
> puts query1.merge(query2).to_sql
WITH "irish_tracks" AS (SELECT "tracks".* FROM "tracks" WHERE (description ilike '%irish%'))
SELECT "tracks"."id", "tracks"."title", "tracks"."description"
FROM "tracks"
JOIN irish_tracks on irish_tracks.id=
WHERE (tracks.bpm > 100)
It merges every single aspect of these two queries.
I've been using @rails for almost 20 years now and I'll never cease to be amazed, surprised, etc. for all of this.
I have a friend who's been a dev longer than I have, uses Java, and just can't understand why the active record pattern is better than his simple use of straight SQL. He doesn't put together queries like I do.tracks.id tracks.id
• • •
Missing some Tweet in this thread? You can try to
force a refresh