1
Phoenix Frameworkを使用して、ここの職場の人々のための「毎日の投票弁当」アプリを作成したいと考えています。私が考えたモデルはVotation
で、各Votationには多くの埋め込みスキーマ(埋め込みスキーマの情報についてはhereを読んでください)が含まれています。モデルは次のように探しています:フェニックスフレームワーク:limitデータベースに1日に挿入
defmodule WhereToLunch.Votation do
use WhereToLunch.Web, :model
schema "votations" do
embeds_many :restaurants, Restaurant
timestamps()
end
@doc """
Builds a changeset based on the `struct` and `params`.
"""
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [])
|> validate_required([])
|> #TODO: Is it !was_votation_inserted_today() ??
end
@doc """
Returns `true` if a `Votation` object was already inserted in the database
on the same day the function is called. Returns false otherwise.
"""
def was_votation_inserted_today() do
#TODO: How to check if a object was already inserted in the database
# on the same day the function is called?
end
end
defmodule WhereToLunch.Restaurant do
use Ecto.Model
embedded_schema do
field :name, :string
field :votes, :integer, default: 0
end
end
私は何をしたいことは一日あたりのテーブル内の複数のInsert
where_to_launch.votations
を許可しないことです。それを行うための最良の方法は何ですか?
データベースのユニークなインデックスを日付フィールドで活用します。 –