File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,38 @@ defmodule Ecto.Integration.ValuesTest do
77 alias Ecto.Integration.Post
88 alias Ecto.Integration.TestRepo
99
10+ test "values works with datetime" do
11+ TestRepo . insert! ( % Post { inserted_at: ~N[ 2000-01-01 00:01:00] } )
12+ TestRepo . insert! ( % Post { inserted_at: ~N[ 2000-01-01 00:02:00] } )
13+ TestRepo . insert! ( % Post { inserted_at: ~N[ 2000-01-01 00:03:00] } )
14+
15+ params = [
16+ % { id: 1 , date: ~N[ 2000-01-01 00:00:00] } ,
17+ % { id: 2 , date: ~N[ 2000-01-01 00:01:00] } ,
18+ % { id: 3 , date: ~N[ 2000-01-01 00:02:00] } ,
19+ % { id: 4 , date: ~N[ 2000-01-01 00:03:00] }
20+ ]
21+
22+ types = % { id: :integer , date: :naive_datetime }
23+
24+ results =
25+ from ( params in values ( params , types ) ,
26+ left_join: p in Post ,
27+ on: p . inserted_at <= params . date ,
28+ group_by: params . id ,
29+ select: % { id: params . id , count: count ( p . id ) } ,
30+ order_by: count ( p . id )
31+ )
32+ |> TestRepo . all ( )
33+
34+ assert results == [
35+ % { count: 0 , id: 1 } ,
36+ % { count: 1 , id: 2 } ,
37+ % { count: 2 , id: 3 } ,
38+ % { count: 3 , id: 4 }
39+ ]
40+ end
41+
1042 test "join to values works" do
1143 TestRepo . insert! ( % Post { id: 1 } )
1244 TestRepo . insert! ( % Comment { post_id: 1 , text: "short" } )
You can’t perform that action at this time.
0 commit comments