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

Fix autocomplete for many_to_many associations #120

Merged
merged 6 commits into from
Jan 28, 2021
Merged

Fix autocomplete for many_to_many associations #120

merged 6 commits into from
Jan 28, 2021

Conversation

damonvjanis
Copy link
Contributor

Using ElixirLS with VS Code, I noticed that schemas with a many_to_many relationship weren't getting autocompletions as I composed ecto queries.

The output was complaining about the %ManyToMany{} struct not having a :related_key, and I traced it back to here. I've confirmed that this change does fix the issue and allows you to get autocompletions for schemas with many_to_many relationships.

Using ElixirLS with VS Code, I noticed that schemas with a many_to_many relationship weren't getting autocompletions as I composed ecto queries.

The output was complaining about the `%ManyToMany{}` struct not having a `:related_key`, and I traced it back to here. I've confirmed that this change does fix the issue and allows you to get autocompletions for schemas with `many_to_many` relationships.
@lukaszsamson
Copy link
Collaborator

@damonvjanis can you add a test case?

@damonvjanis
Copy link
Contributor Author

@lukaszsamson I got one added. I think the new fake schema is correct, but I'm not an expert on Ecto internals. The Ecto.Association.ManyToMany struct (https://github.com/elixir-ecto/ecto/blob/v3.5.6/lib/ecto/association.ex#L1003) doesn't define a related_key field which is what causes the issue I observed, and so when I added a many_to_many association in the fakes that way some tests started failing, but the suggested change I have fixes them. I added another test that is functionally identical to the one above it, but is labeled clearly to make the documentation more explicit.

damonvjanis and others added 3 commits January 26, 2021 06:42
Remove unused code
Mix format
@lukaszsamson lukaszsamson merged commit ec5fd93 into elixir-lsp:master Jan 28, 2021
@lukaszsamson
Copy link
Collaborator

Thanks

@damonvjanis damonvjanis deleted the patch-1 branch January 28, 2021 15:26
lukaszsamson added a commit to elixir-lsp/elixir-ls that referenced this pull request Jan 29, 2021
Fixes crash with ecto many to many completions
elixir-lsp/elixir_sense#120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants