fix selecting list of fields and map/2 from subquery - #4777
Conversation
|
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]) |
There was a problem hiding this comment.
@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]))
There was a problem hiding this comment.
Yeah, select: [:foo, :bar] keeps whatever the from clause is. Structs if there are source+schema, maps if we only have the source.
There was a problem hiding this comment.
ah ok I believe what I just pushed now is the correct solution then. sorry for the back and forth. would you mind taking a look once more?
Closes #4776