🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 kürzlich 3 Min Lesezeit
0

includes vs joins vs preload vs eager_load in Rails

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

These four all deal with associations, and they're easy to mix up. The way I keep them straight is to ask two questions about each: what SQL does it run, and does it actually pull the associated records into memory? Once you can answer both, picking the right one is straightforward.






































Method SQL it generates Loads the association? Reach for it when
joins INNER JOIN No You filter or sort by the associated table
preload Separate queries, one per association Yes You'll read the association and want it loaded separately
eager_load A single LEFT OUTER JOIN Yes You need to read and filter by the association in one query
includes Rails picks preload or eager_load Yes The default for killing N+1 when you're not sure which you need





joins



joins builds a SQL join but does not load anything into memory. User.joins(:posts).where(posts: { published: true }) filters users by their posts cheaply. But if you then call user.posts in Ruby, you get a fresh query for every user, which is the N+1 you were trying to avoid, because the posts were never loaded. Use joins to filter and sort, not to display.






preload



preload always runs separate queries, one for the users and one for their posts, then stitches them together in memory. There is no join, so you can't reference the posts table in a where. Try it and Rails will complain.






eager_load



eager_load forces a single LEFT OUTER JOIN and builds the association out of the joined rows. Unlike preload, it still works when you filter on the joined table, because the join is right there in the query.






includes



includes is the one I reach for most. You're telling Rails what you want ("load these associations, don't N+1 me") and letting it choose the strategy. By default it preloads with separate queries. The moment you reference the associated table in a where or order, it switches to eager_load and runs the join instead. You usually don't have to think about which.






Putting it to work



Two quick cases to make it stick.



To list users along with their posts, use User.includes(:posts). You're displaying the association, so separate queries are fine and you've killed the N+1.



To find only the users who have published posts, use User.joins(:posts).where(posts: { published: true }). You're filtering by the association and you never need the post objects in memory, so there's no reason to load them. If you want to filter and then display those posts, use includes together with references, or just use eager_load.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten includes vs joins vs preload vs eager_load in Rails

Thematisch verwandte Begriffe: includes, joins, preload, eagerload · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...