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

Check for named binding before joining #537

Merged
merged 1 commit into from
Aug 29, 2024
Merged

Conversation

Flo0807
Copy link
Collaborator

@Flo0807 Flo0807 commented Aug 23, 2024

closes #530

This PR checks for a named binding before joining. It prevents an error being thrown if a join with the same alias has already been performed, e.g. in the item_query function.

However, if we do not explicitly set an alias when joining in item_query this will not prevent a second join from being performed.

Consider a post belonging to a user. If we define an item query like this.

@impl Backpex.LiveResource
def item_query(query, live_action, assigns) do
  query
  |> join(:left, [p], u in Demo.User, on: u.id == p.user_id)
end

maybe_join will do a second join because there is no alias userhas_named_binding/2 returns false.

If we want to prevent a second join to be performed, we have to set the user alias explicitly:

@impl Backpex.LiveResource
def item_query(query, live_action, assigns) do
  query
  |> join(:left, [p], u in Demo.User, on: u.id == p.user_id, as: :user)
end

@Flo0807 Flo0807 self-assigned this Aug 23, 2024
@Flo0807 Flo0807 added the bug Something isn't working label Aug 23, 2024
@Flo0807 Flo0807 requested a review from krns August 23, 2024 07:12
@krns krns merged commit 51927dd into develop Aug 29, 2024
6 checks passed
@krns krns deleted the feature/530-check-for-join branch August 29, 2024 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

maybe_join/2 should check if join was already added
2 participants