Skip to content
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

belongs to relationship won't show without preloading, but preloading is not necessary #193

Closed
strzibny opened this issue Apr 4, 2019 · 3 comments

Comments

@strzibny
Copy link
Contributor

strzibny commented Apr 4, 2019

Hello all,

I am trying to implement JSON:API endpoints where I have belongs_to relationship so the ID is directly in the loaded table, but this library (probably because of #103) won't show these relationships unless they are explicitely loaded.

I think preloading the belongs_to relationship makes no sense as we only display the ID and type. For has_many relationship, the current behaviour is of course desirable.

Here is a workaround by setting the relationship by hand:

def show(conn, %{"id" => id}) do
    object = Document.get_document{(%{login_id: conn.assigns[:login_id], id: id})

    object = %{object | folder: %{id: object.folder_id}}
    render(conn, "show.json", data: object)
end

After this the folder relationship will be included and no other SQL queries (or joins) need to happen...

What do you think? Am I missing something?

@jherdman
Copy link
Contributor

jherdman commented Apr 4, 2019

I totally agree with you. I've been trying to come up with a resolution to this in #174 , but I'm a bit drained for time at the moment. The biggest challenge as I see it is changing how relationships work whilst providing a clean upgrade path.

Copy link
Contributor

This issue has been automatically marked as "stale:discard". We are sorry that we haven't been able to prioritize it yet.
If this issue still relevant, please leave any comment if you have any new additional information that helps to solve this issue. We encourage you to create a pull request, if you can. We are happy to help you with that.

Copy link
Contributor

Closing this issue after a prolonged period of inactivity. If this issue is still relevant, feel free to re-open the issue. Thank you!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants