Skip to content

fix selecting list of fields and map/2 from subquery - #4777

Open
greg-rychlewski wants to merge 6 commits into
elixir-ecto:masterfrom
greg-rychlewski:select_from_subquery_fix
Open

fix selecting list of fields and map/2 from subquery#4777
greg-rychlewski wants to merge 6 commits into
elixir-ecto:masterfrom
greg-rychlewski:select_from_subquery_fix

Conversation

@greg-rychlewski

Copy link
Copy Markdown
Member

Closes #4776

@greg-rychlewski

Copy link
Copy Markdown
Member Author

ah there is some inspect stuff and old tests i need to fix up

assert query.select.fields == [{{:., [type: :string], [{:&, [], [1]}, :title]}, [], []}]

subquery = from p in Post, select: %{id: p.id, title: p.title}
subquery = from p in Post, select: struct(p, [:id, :title])

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josevalim The fix was surfacing an error in this test. Basically it fails now because select: [atom()] is considered the same as struct/2 more strictly.

Just want to make sure this is still the right interpretation of the list of atoms. It's in the docs but not sure if it's out of date

It is also possible to select a struct and limit the returned fields at the same time:

from(City, select: [:name])

The syntax above is equivalent to:

from(city in City, select: struct(city, [:name]))

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.

select: map(source, fields) and select: [:fields] lose field types when the source is a subquery

2 participants