Most performant way to load associations in rails

tfantina

I'm trying to load a nested association, a User can belong to many Groups and I want to load all Posts from Groups where the user is a member, but only the posts no the groups as well.

Something like current_user.groups.eager_load(:posts), but without nesting posts under groups.

Alex

I'm assuming Post belongs to Group here.

Start with the model that you need to load and build the query from there. If user belongs to 2 groups here, this will load all the posts from those 2 groups.

Post.where(group: current_user.groups)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Most performant way to load textures from a Spritekit texture atlas

Performant way to load site navigation from a DB table in Rails

Most Performant Way To Do Imports

Most performant way to check if elements are overlapping

Most performant way to draw text on a curve, and animate it?

What is the most performant way to concatenate a string with a separator

What is the most performant way to write a string to a file?

Most performant way to crawl json object array

What is the most performant way to rewrite a large IN clause?

Prisma: Most performant way to query for sub relations

Eager Load indirect associations Rails

|Rust| What's the most performant way of initializing a BIG and RANDOMIZED array?

Most performant way to filter a huge List in C#?

In JS what is the most performant way to quickly store XY coordinate integers

C#/.NET Most performant way to call a method dynamically

React: Traversing nested Objects in state to prevent duplicates – most performant way?

Most performant way to test if one vector is permutation of another

What's the most performant way to do simple IP address comparisons?

What's the most performant way to reverse a lookup on a dict of tuples?

iOS: what's the fastest, most performant way to make a screenshot programmatically?

Most performant way to create a JavaScript collection with generated IDs

Most performant way to insert thousands of rows of data into Azure SQL DB?

most performant way to get asof price given a list of timestamps

What is the most performant way to determine if a year is a leap year in Swift?

What is the most performant way to query Process Performance Counters?

What is the most performant way to create the following MATCH statement and why?

Most performant way to filter on multiple values in multiple columns?

What is the most performant way to render unmanaged video frames in WPF?

Most performant binding to this in React?

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive