New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetching joined records alongside with main entity #287
Comments
Hi, loading association via join is not supported at the moment, the only way to load association at the moment is by using different preload query |
Thanks for reply. I actually figured out kind of workaround by creating a new struct with fields from both entities, something like
I'm using |
Thanks for this suggestion, it's actually not very hard to implement as long as has many association is not supported for this kind of use case I've created a PR to support this: #290 |
Hey,
I wonder what would be suggested approach to fetch composite records (those combined of entity and a join entity). In the documentation there is example on how to perform join and then filter results by values in joined tables, but there is nothing about fetching these joined records.
As an example, I want to describe a simplified version of issue I'm having. Data model here does not make much sense, but it's just to illustrate the problem. Let's say we have a table of users (id, name) and a separate table with number of user followers (user_id, followers_count), it's a one-to-one relation.
I want to be able to find users with certain number of followers so I can use join and then where clause, but I would like to also fetch number of followers in the same query (it's joined already anyway) instead of using prefetch.
This code example above will only populate user data, then I can preload
follower_stats
for each user, but it seems somewhat wasteful as number of users can be pretty high.The text was updated successfully, but these errors were encountered: