2017-02-06 12 views
0

inserted_atレコードを選択:エクト:私は非常に単純な<a href="http://www.phoenixframework.org/docs/ecto-models" rel="nofollow noreferrer">Ecto model</a>を持っている特定の日付

defmodule MyApp.User do 
    use MyApp.Web, :model 

    schema "users" do 
    field :name, :string 
    timestamps() 
    end 

    @doc """ 
    Builds a changeset based on the `struct` and `params`. 
    """ 
    def changeset(struct, params \\ %{}) do 
    struct 
    |> cast(params, []) 
    |> validate_required([]) 
    end 
end 

と移行:

defmodule MyApp.Repo.Migrations.CreateUser do 
    use Ecto.Migration 

    def down do 
    drop table(:users) 
    end 

    def change do 
    drop_if_exists table(:users) 
    create table(:users) do 
     add :name, :string 
     timestamps() 
    end 
    end 

end 

私はinserted_at特定の日付(のためだったすべての人usersを選択したいです今日、例)。それをする最善の方法は何ですか?

答えて

2

私はEctoだけでこれを行う方法がわかりません。ですから、この答えはSQL固有のものになります。私はこれをPostreSQLで試しただけです。

Attendance.Repo.all(from s in Something, 
        where: fragment("date(inserted_at) = ?", ^~D[2017-02-06])) 
関連する問題