Preload with order_by from another table with Ecto
up vote
0
down vote
favorite
I have an issue with the order of some preloads.
Basically I have a structure like: Restaurant > FoodItem > OptionGroup
.
An OptionGroup
is associated to a Restaurant
, and can be associated to a FoodItem
(table with many_to_many FoodItemOptionGroup
).
In the food_item.ex
I have the following:
many_to_many(
:option_groups,
OptionGroup,
join_through: FoodItemOptionGroup,
on_delete: :delete_all
)
I allow the front end to query the API with the preloads they need, so they can do something like: ?include=food_item.option_groups
. The function iterate and create a preload structure. This is the core part:
is_atom(value) ->
case value do
:food_items ->
[{:food_items, from(p in FoodItem, order_by: [p.id])}]
:option_groups ->
[{:option_groups, from(og in OptionGroup, order_by: og.id)}]
:food_extras ->
[{:food_extras, from(fe in FoodExtra, order_by: fe.id)}]
end
Recently I've implement an row_weight
that allows me to order by it's value. On FoodItem
it was simple, just add order_by and it's done. On OptionGroups
, it's been complicated. Because the row_weight
is on the association many_to_many FoodItemOptionGroup
, the preload doesn't work properly.
is_atom(value) ->
case value do
:food_items ->
[{:food_items, from(p in FoodItem, order_by: [p.row_weight, p.id])}]
:option_groups ->
[
{
:option_groups,
OptionGroup
|> join(
:inner,
[og],
fiog in Ketchup.FoodItemOptionGroup,
og.id == fiog.option_group_id
)
|> order_by([og, fiog], [fiog.row_weight, og.id])
}
]
:food_extras ->
[{:food_extras, from(fe in FoodExtra, order_by: fe.id)}]
end
This will result in multiple option_groups
being duplicated by the number of associations they are to other food_items
. It seams that preload pick only the right ones, for example Temperature
and Spice
and also take all the other Temperature
and Spice
(they share the same id
because are the some) of other food_items
.
There was a possible solution to use group_by
, because I think it doesn't affect the output OptionGroup
.
OptionGroup
|> join(:inner, [og], fiog in Ketchup.FoodItemOptionGroup, og.id == fiog.option_group_id)
|> order_by([og, fiog], [fiog.row_weight, og.id])
|> group_by([og, fiog], [og.id, fiog.row_weight])
But will give the following error if run as a preload. If run as a standard query it does retrieve the right OptionGroups
.
** (Postgrex.Error) ERROR 42803 (grouping_error): column "f2.id" must appear in the GROUP BY clause or be used in an aggregate function
In the first example, it looks like it need a filter by food_item_id
, but the only way to do that is using function in preload.
fn food_items_ids ->
OptionGroup
|> join(:inner, [og], fiog in Ketchup.FoodItemOptionGroup,
og.id == fiog.option_group_id and fiog.food_item_id in ^food_items_ids)
|> order_by([og, fiog], [fiog.row_weight, og.id])
|> Ketchup.Repo.all()
end
But in this scenario, what the preload will do is to only add the OptionGroup
that have the same id
as the FoodItem
.
I think I'm out of options to try here, I'm thinking in probably right one query without options to select which preloads you want or not.
EDIT
This is the preload I'm sending to Ecto:
GET ../endpoint1?include=option_groups
[
option_groups: #Ecto.Query<from o in Ketchup.OptionGroup,
join: f in Ketchup.FoodItemOptionGroup, on: o.id == f.option_group_id,
order_by: [asc: f.row_weight, asc: o.id]>
]
I'm displaying here without distinct, but it distinct it will show all OptionGroups, but it will not order them because row_weight aren't available in all of them, when I just want the one with the connection with FoodItem
that have row_weight
.
GET ../endpoint2?include=food_items.option_groups.food_extras
[
food_items: #Ecto.Query<from f in Ketchup.FoodItem,
order_by: [asc: f.row_weight, asc: f.id]>,
food_items: [
option_groups: #Ecto.Query<from o in Ketchup.OptionGroup,
join: f in Ketchup.FoodItemOptionGroup, on: o.id == f.option_group_id,
order_by: [asc: f.row_weight, asc: o.id], distinct: [asc: o.id]>
]
]
EDIT2
So, I end up using a query. I will be trying to implement GraphQL in the future.
FoodCategory
|> join(:inner, [fc], r in Restaurant, r.id == fc.restaurant_id)
|> join(:left, [fc, r], fi in Ketchup.FoodItem, fi.food_category_id == fc.id)
|> join(:left, [fc, r, fi], fiog in Ketchup.FoodItemOptionGroup, fiog.food_item_id == fi.id)
|> join(:left, [fc, r, fi, fiog], og in Ketchup.OptionGroup, og.id == fiog.option_group_id)
|> join(
:left,
[fc, r, fi, fiog, og],
ogfe in Ketchup.OptionGroupFoodExtra,
ogfe.option_group_id == og.id
)
|> join(
:left,
[fc, r, fi, fiog, og, ogfe],
fe in Ketchup.FoodExtra,
ogfe.food_extra_id == fe.id
)
|> where([fc], fc.restaurant_id == ^restaurant_id)
|> preload(
[fc, r, fi, fiog, og, ogfe, fe],
food_items: {fi, option_groups: {og, food_extras: fe}}
)
|> order_by([fc, r, fi, fiog, og, ogfe, fe], [fc.row_weight, fi.row_weight, fiog.row_weight])
elixir ecto
add a comment |
up vote
0
down vote
favorite
I have an issue with the order of some preloads.
Basically I have a structure like: Restaurant > FoodItem > OptionGroup
.
An OptionGroup
is associated to a Restaurant
, and can be associated to a FoodItem
(table with many_to_many FoodItemOptionGroup
).
In the food_item.ex
I have the following:
many_to_many(
:option_groups,
OptionGroup,
join_through: FoodItemOptionGroup,
on_delete: :delete_all
)
I allow the front end to query the API with the preloads they need, so they can do something like: ?include=food_item.option_groups
. The function iterate and create a preload structure. This is the core part:
is_atom(value) ->
case value do
:food_items ->
[{:food_items, from(p in FoodItem, order_by: [p.id])}]
:option_groups ->
[{:option_groups, from(og in OptionGroup, order_by: og.id)}]
:food_extras ->
[{:food_extras, from(fe in FoodExtra, order_by: fe.id)}]
end
Recently I've implement an row_weight
that allows me to order by it's value. On FoodItem
it was simple, just add order_by and it's done. On OptionGroups
, it's been complicated. Because the row_weight
is on the association many_to_many FoodItemOptionGroup
, the preload doesn't work properly.
is_atom(value) ->
case value do
:food_items ->
[{:food_items, from(p in FoodItem, order_by: [p.row_weight, p.id])}]
:option_groups ->
[
{
:option_groups,
OptionGroup
|> join(
:inner,
[og],
fiog in Ketchup.FoodItemOptionGroup,
og.id == fiog.option_group_id
)
|> order_by([og, fiog], [fiog.row_weight, og.id])
}
]
:food_extras ->
[{:food_extras, from(fe in FoodExtra, order_by: fe.id)}]
end
This will result in multiple option_groups
being duplicated by the number of associations they are to other food_items
. It seams that preload pick only the right ones, for example Temperature
and Spice
and also take all the other Temperature
and Spice
(they share the same id
because are the some) of other food_items
.
There was a possible solution to use group_by
, because I think it doesn't affect the output OptionGroup
.
OptionGroup
|> join(:inner, [og], fiog in Ketchup.FoodItemOptionGroup, og.id == fiog.option_group_id)
|> order_by([og, fiog], [fiog.row_weight, og.id])
|> group_by([og, fiog], [og.id, fiog.row_weight])
But will give the following error if run as a preload. If run as a standard query it does retrieve the right OptionGroups
.
** (Postgrex.Error) ERROR 42803 (grouping_error): column "f2.id" must appear in the GROUP BY clause or be used in an aggregate function
In the first example, it looks like it need a filter by food_item_id
, but the only way to do that is using function in preload.
fn food_items_ids ->
OptionGroup
|> join(:inner, [og], fiog in Ketchup.FoodItemOptionGroup,
og.id == fiog.option_group_id and fiog.food_item_id in ^food_items_ids)
|> order_by([og, fiog], [fiog.row_weight, og.id])
|> Ketchup.Repo.all()
end
But in this scenario, what the preload will do is to only add the OptionGroup
that have the same id
as the FoodItem
.
I think I'm out of options to try here, I'm thinking in probably right one query without options to select which preloads you want or not.
EDIT
This is the preload I'm sending to Ecto:
GET ../endpoint1?include=option_groups
[
option_groups: #Ecto.Query<from o in Ketchup.OptionGroup,
join: f in Ketchup.FoodItemOptionGroup, on: o.id == f.option_group_id,
order_by: [asc: f.row_weight, asc: o.id]>
]
I'm displaying here without distinct, but it distinct it will show all OptionGroups, but it will not order them because row_weight aren't available in all of them, when I just want the one with the connection with FoodItem
that have row_weight
.
GET ../endpoint2?include=food_items.option_groups.food_extras
[
food_items: #Ecto.Query<from f in Ketchup.FoodItem,
order_by: [asc: f.row_weight, asc: f.id]>,
food_items: [
option_groups: #Ecto.Query<from o in Ketchup.OptionGroup,
join: f in Ketchup.FoodItemOptionGroup, on: o.id == f.option_group_id,
order_by: [asc: f.row_weight, asc: o.id], distinct: [asc: o.id]>
]
]
EDIT2
So, I end up using a query. I will be trying to implement GraphQL in the future.
FoodCategory
|> join(:inner, [fc], r in Restaurant, r.id == fc.restaurant_id)
|> join(:left, [fc, r], fi in Ketchup.FoodItem, fi.food_category_id == fc.id)
|> join(:left, [fc, r, fi], fiog in Ketchup.FoodItemOptionGroup, fiog.food_item_id == fi.id)
|> join(:left, [fc, r, fi, fiog], og in Ketchup.OptionGroup, og.id == fiog.option_group_id)
|> join(
:left,
[fc, r, fi, fiog, og],
ogfe in Ketchup.OptionGroupFoodExtra,
ogfe.option_group_id == og.id
)
|> join(
:left,
[fc, r, fi, fiog, og, ogfe],
fe in Ketchup.FoodExtra,
ogfe.food_extra_id == fe.id
)
|> where([fc], fc.restaurant_id == ^restaurant_id)
|> preload(
[fc, r, fi, fiog, og, ogfe, fe],
food_items: {fi, option_groups: {og, food_extras: fe}}
)
|> order_by([fc, r, fi, fiog, og, ogfe, fe], [fc.row_weight, fi.row_weight, fiog.row_weight])
elixir ecto
Can't you use distinct instead ofgroup_by
? I think appending|> distinct(true)
to your query would work.
– Gabriel Prá
Nov 21 at 4:29
@GabrielPrá,|> distinct(true)
doesn't work.ERROR 42P10 (invalid_column_reference): for SELECT DISTINCT, ORDER BY expressions must appear in select list
.|> distinct([og], og.id)
works, but with a weird, in one endpoint it limits to 4 option groups, in another it show them all.
– David Magalhães
Nov 22 at 1:47
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have an issue with the order of some preloads.
Basically I have a structure like: Restaurant > FoodItem > OptionGroup
.
An OptionGroup
is associated to a Restaurant
, and can be associated to a FoodItem
(table with many_to_many FoodItemOptionGroup
).
In the food_item.ex
I have the following:
many_to_many(
:option_groups,
OptionGroup,
join_through: FoodItemOptionGroup,
on_delete: :delete_all
)
I allow the front end to query the API with the preloads they need, so they can do something like: ?include=food_item.option_groups
. The function iterate and create a preload structure. This is the core part:
is_atom(value) ->
case value do
:food_items ->
[{:food_items, from(p in FoodItem, order_by: [p.id])}]
:option_groups ->
[{:option_groups, from(og in OptionGroup, order_by: og.id)}]
:food_extras ->
[{:food_extras, from(fe in FoodExtra, order_by: fe.id)}]
end
Recently I've implement an row_weight
that allows me to order by it's value. On FoodItem
it was simple, just add order_by and it's done. On OptionGroups
, it's been complicated. Because the row_weight
is on the association many_to_many FoodItemOptionGroup
, the preload doesn't work properly.
is_atom(value) ->
case value do
:food_items ->
[{:food_items, from(p in FoodItem, order_by: [p.row_weight, p.id])}]
:option_groups ->
[
{
:option_groups,
OptionGroup
|> join(
:inner,
[og],
fiog in Ketchup.FoodItemOptionGroup,
og.id == fiog.option_group_id
)
|> order_by([og, fiog], [fiog.row_weight, og.id])
}
]
:food_extras ->
[{:food_extras, from(fe in FoodExtra, order_by: fe.id)}]
end
This will result in multiple option_groups
being duplicated by the number of associations they are to other food_items
. It seams that preload pick only the right ones, for example Temperature
and Spice
and also take all the other Temperature
and Spice
(they share the same id
because are the some) of other food_items
.
There was a possible solution to use group_by
, because I think it doesn't affect the output OptionGroup
.
OptionGroup
|> join(:inner, [og], fiog in Ketchup.FoodItemOptionGroup, og.id == fiog.option_group_id)
|> order_by([og, fiog], [fiog.row_weight, og.id])
|> group_by([og, fiog], [og.id, fiog.row_weight])
But will give the following error if run as a preload. If run as a standard query it does retrieve the right OptionGroups
.
** (Postgrex.Error) ERROR 42803 (grouping_error): column "f2.id" must appear in the GROUP BY clause or be used in an aggregate function
In the first example, it looks like it need a filter by food_item_id
, but the only way to do that is using function in preload.
fn food_items_ids ->
OptionGroup
|> join(:inner, [og], fiog in Ketchup.FoodItemOptionGroup,
og.id == fiog.option_group_id and fiog.food_item_id in ^food_items_ids)
|> order_by([og, fiog], [fiog.row_weight, og.id])
|> Ketchup.Repo.all()
end
But in this scenario, what the preload will do is to only add the OptionGroup
that have the same id
as the FoodItem
.
I think I'm out of options to try here, I'm thinking in probably right one query without options to select which preloads you want or not.
EDIT
This is the preload I'm sending to Ecto:
GET ../endpoint1?include=option_groups
[
option_groups: #Ecto.Query<from o in Ketchup.OptionGroup,
join: f in Ketchup.FoodItemOptionGroup, on: o.id == f.option_group_id,
order_by: [asc: f.row_weight, asc: o.id]>
]
I'm displaying here without distinct, but it distinct it will show all OptionGroups, but it will not order them because row_weight aren't available in all of them, when I just want the one with the connection with FoodItem
that have row_weight
.
GET ../endpoint2?include=food_items.option_groups.food_extras
[
food_items: #Ecto.Query<from f in Ketchup.FoodItem,
order_by: [asc: f.row_weight, asc: f.id]>,
food_items: [
option_groups: #Ecto.Query<from o in Ketchup.OptionGroup,
join: f in Ketchup.FoodItemOptionGroup, on: o.id == f.option_group_id,
order_by: [asc: f.row_weight, asc: o.id], distinct: [asc: o.id]>
]
]
EDIT2
So, I end up using a query. I will be trying to implement GraphQL in the future.
FoodCategory
|> join(:inner, [fc], r in Restaurant, r.id == fc.restaurant_id)
|> join(:left, [fc, r], fi in Ketchup.FoodItem, fi.food_category_id == fc.id)
|> join(:left, [fc, r, fi], fiog in Ketchup.FoodItemOptionGroup, fiog.food_item_id == fi.id)
|> join(:left, [fc, r, fi, fiog], og in Ketchup.OptionGroup, og.id == fiog.option_group_id)
|> join(
:left,
[fc, r, fi, fiog, og],
ogfe in Ketchup.OptionGroupFoodExtra,
ogfe.option_group_id == og.id
)
|> join(
:left,
[fc, r, fi, fiog, og, ogfe],
fe in Ketchup.FoodExtra,
ogfe.food_extra_id == fe.id
)
|> where([fc], fc.restaurant_id == ^restaurant_id)
|> preload(
[fc, r, fi, fiog, og, ogfe, fe],
food_items: {fi, option_groups: {og, food_extras: fe}}
)
|> order_by([fc, r, fi, fiog, og, ogfe, fe], [fc.row_weight, fi.row_weight, fiog.row_weight])
elixir ecto
I have an issue with the order of some preloads.
Basically I have a structure like: Restaurant > FoodItem > OptionGroup
.
An OptionGroup
is associated to a Restaurant
, and can be associated to a FoodItem
(table with many_to_many FoodItemOptionGroup
).
In the food_item.ex
I have the following:
many_to_many(
:option_groups,
OptionGroup,
join_through: FoodItemOptionGroup,
on_delete: :delete_all
)
I allow the front end to query the API with the preloads they need, so they can do something like: ?include=food_item.option_groups
. The function iterate and create a preload structure. This is the core part:
is_atom(value) ->
case value do
:food_items ->
[{:food_items, from(p in FoodItem, order_by: [p.id])}]
:option_groups ->
[{:option_groups, from(og in OptionGroup, order_by: og.id)}]
:food_extras ->
[{:food_extras, from(fe in FoodExtra, order_by: fe.id)}]
end
Recently I've implement an row_weight
that allows me to order by it's value. On FoodItem
it was simple, just add order_by and it's done. On OptionGroups
, it's been complicated. Because the row_weight
is on the association many_to_many FoodItemOptionGroup
, the preload doesn't work properly.
is_atom(value) ->
case value do
:food_items ->
[{:food_items, from(p in FoodItem, order_by: [p.row_weight, p.id])}]
:option_groups ->
[
{
:option_groups,
OptionGroup
|> join(
:inner,
[og],
fiog in Ketchup.FoodItemOptionGroup,
og.id == fiog.option_group_id
)
|> order_by([og, fiog], [fiog.row_weight, og.id])
}
]
:food_extras ->
[{:food_extras, from(fe in FoodExtra, order_by: fe.id)}]
end
This will result in multiple option_groups
being duplicated by the number of associations they are to other food_items
. It seams that preload pick only the right ones, for example Temperature
and Spice
and also take all the other Temperature
and Spice
(they share the same id
because are the some) of other food_items
.
There was a possible solution to use group_by
, because I think it doesn't affect the output OptionGroup
.
OptionGroup
|> join(:inner, [og], fiog in Ketchup.FoodItemOptionGroup, og.id == fiog.option_group_id)
|> order_by([og, fiog], [fiog.row_weight, og.id])
|> group_by([og, fiog], [og.id, fiog.row_weight])
But will give the following error if run as a preload. If run as a standard query it does retrieve the right OptionGroups
.
** (Postgrex.Error) ERROR 42803 (grouping_error): column "f2.id" must appear in the GROUP BY clause or be used in an aggregate function
In the first example, it looks like it need a filter by food_item_id
, but the only way to do that is using function in preload.
fn food_items_ids ->
OptionGroup
|> join(:inner, [og], fiog in Ketchup.FoodItemOptionGroup,
og.id == fiog.option_group_id and fiog.food_item_id in ^food_items_ids)
|> order_by([og, fiog], [fiog.row_weight, og.id])
|> Ketchup.Repo.all()
end
But in this scenario, what the preload will do is to only add the OptionGroup
that have the same id
as the FoodItem
.
I think I'm out of options to try here, I'm thinking in probably right one query without options to select which preloads you want or not.
EDIT
This is the preload I'm sending to Ecto:
GET ../endpoint1?include=option_groups
[
option_groups: #Ecto.Query<from o in Ketchup.OptionGroup,
join: f in Ketchup.FoodItemOptionGroup, on: o.id == f.option_group_id,
order_by: [asc: f.row_weight, asc: o.id]>
]
I'm displaying here without distinct, but it distinct it will show all OptionGroups, but it will not order them because row_weight aren't available in all of them, when I just want the one with the connection with FoodItem
that have row_weight
.
GET ../endpoint2?include=food_items.option_groups.food_extras
[
food_items: #Ecto.Query<from f in Ketchup.FoodItem,
order_by: [asc: f.row_weight, asc: f.id]>,
food_items: [
option_groups: #Ecto.Query<from o in Ketchup.OptionGroup,
join: f in Ketchup.FoodItemOptionGroup, on: o.id == f.option_group_id,
order_by: [asc: f.row_weight, asc: o.id], distinct: [asc: o.id]>
]
]
EDIT2
So, I end up using a query. I will be trying to implement GraphQL in the future.
FoodCategory
|> join(:inner, [fc], r in Restaurant, r.id == fc.restaurant_id)
|> join(:left, [fc, r], fi in Ketchup.FoodItem, fi.food_category_id == fc.id)
|> join(:left, [fc, r, fi], fiog in Ketchup.FoodItemOptionGroup, fiog.food_item_id == fi.id)
|> join(:left, [fc, r, fi, fiog], og in Ketchup.OptionGroup, og.id == fiog.option_group_id)
|> join(
:left,
[fc, r, fi, fiog, og],
ogfe in Ketchup.OptionGroupFoodExtra,
ogfe.option_group_id == og.id
)
|> join(
:left,
[fc, r, fi, fiog, og, ogfe],
fe in Ketchup.FoodExtra,
ogfe.food_extra_id == fe.id
)
|> where([fc], fc.restaurant_id == ^restaurant_id)
|> preload(
[fc, r, fi, fiog, og, ogfe, fe],
food_items: {fi, option_groups: {og, food_extras: fe}}
)
|> order_by([fc, r, fi, fiog, og, ogfe, fe], [fc.row_weight, fi.row_weight, fiog.row_weight])
elixir ecto
elixir ecto
edited Nov 24 at 11:11
asked Nov 20 at 17:05
David Magalhães
3043613
3043613
Can't you use distinct instead ofgroup_by
? I think appending|> distinct(true)
to your query would work.
– Gabriel Prá
Nov 21 at 4:29
@GabrielPrá,|> distinct(true)
doesn't work.ERROR 42P10 (invalid_column_reference): for SELECT DISTINCT, ORDER BY expressions must appear in select list
.|> distinct([og], og.id)
works, but with a weird, in one endpoint it limits to 4 option groups, in another it show them all.
– David Magalhães
Nov 22 at 1:47
add a comment |
Can't you use distinct instead ofgroup_by
? I think appending|> distinct(true)
to your query would work.
– Gabriel Prá
Nov 21 at 4:29
@GabrielPrá,|> distinct(true)
doesn't work.ERROR 42P10 (invalid_column_reference): for SELECT DISTINCT, ORDER BY expressions must appear in select list
.|> distinct([og], og.id)
works, but with a weird, in one endpoint it limits to 4 option groups, in another it show them all.
– David Magalhães
Nov 22 at 1:47
Can't you use distinct instead of
group_by
? I think appending |> distinct(true)
to your query would work.– Gabriel Prá
Nov 21 at 4:29
Can't you use distinct instead of
group_by
? I think appending |> distinct(true)
to your query would work.– Gabriel Prá
Nov 21 at 4:29
@GabrielPrá,
|> distinct(true)
doesn't work. ERROR 42P10 (invalid_column_reference): for SELECT DISTINCT, ORDER BY expressions must appear in select list
. |> distinct([og], og.id)
works, but with a weird, in one endpoint it limits to 4 option groups, in another it show them all.– David Magalhães
Nov 22 at 1:47
@GabrielPrá,
|> distinct(true)
doesn't work. ERROR 42P10 (invalid_column_reference): for SELECT DISTINCT, ORDER BY expressions must appear in select list
. |> distinct([og], og.id)
works, but with a weird, in one endpoint it limits to 4 option groups, in another it show them all.– David Magalhães
Nov 22 at 1:47
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398017%2fpreload-with-order-by-from-another-table-with-ecto%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398017%2fpreload-with-order-by-from-another-table-with-ecto%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can't you use distinct instead of
group_by
? I think appending|> distinct(true)
to your query would work.– Gabriel Prá
Nov 21 at 4:29
@GabrielPrá,
|> distinct(true)
doesn't work.ERROR 42P10 (invalid_column_reference): for SELECT DISTINCT, ORDER BY expressions must appear in select list
.|> distinct([og], og.id)
works, but with a weird, in one endpoint it limits to 4 option groups, in another it show them all.– David Magalhães
Nov 22 at 1:47