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

Automatically set first order_by when distinct set #504

Merged
merged 2 commits into from
Mar 8, 2015

Conversation

gjaldon
Copy link
Contributor

@gjaldon gjaldon commented Mar 5, 2015

Addresses this issue: #495

My initial implementation for this enhancement but will need to add docs and test it some more.

@@ -213,12 +213,16 @@ if Code.ensure_loaded?(Postgrex.Connection) do
end
end

defp order_by(order_bys, sources) do
defp order_by([], _distincts, _sources), do: nil
Copy link
Member

Choose a reason for hiding this comment

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

If order_by is empty, we should still generate the order by for distincts.

@ericmj
Copy link
Member

ericmj commented Mar 5, 2015

It would be more efficient to build the SQL for distinct once and reuse that in order_by. Would that be possible?

@josevalim
Copy link
Member

@ericmj yeah.

@gjaldon gjaldon force-pushed the automatically-set-order-by branch 2 times, most recently from 25f0282 to 68e8ef6 Compare March 8, 2015 18:27
@gjaldon gjaldon changed the title [WIP] Automatically set first order_by when distinct set Automatically set first order_by when distinct set Mar 8, 2015
@gjaldon
Copy link
Contributor Author

gjaldon commented Mar 8, 2015

@josevalim @ericmj are the latest changes okay?

"" -> nil
_ -> "ORDER BY " <> exprs
case {distinct_exprs, exprs, distinct} do
{_, "", _} -> nil
Copy link
Member

Choose a reason for hiding this comment

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

We should add the distinct_exprs to order by even if there is no order_by, no?

Copy link
Member

Choose a reason for hiding this comment

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

@ericmj said no. :)

josevalim added a commit that referenced this pull request Mar 8, 2015
Automatically set first order_by when distinct set
@josevalim josevalim merged commit 88b86ae into elixir-ecto:master Mar 8, 2015
@josevalim
Copy link
Member

❤️ 💚 💙 💛 💜

@gjaldon
Copy link
Contributor Author

gjaldon commented Mar 9, 2015

Thanks, guys! 👍

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.

None yet

3 participants