Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update phoenix.new and generators to Ecto 2.0
- Loading branch information
José Valim
committed
Apr 17, 2016
1 parent
613ff4b
commit 8b560cd
Showing
10 changed files
with
36 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
ExUnit.start | ||
<%= if ecto do %> | ||
Mix.Task.run "ecto.create", ~w(-r <%= application_module %>.Repo --quiet) | ||
Mix.Task.run "ecto.migrate", ~w(-r <%= application_module %>.Repo --quiet) | ||
<%= adapter_config[:test_begin] %> | ||
<%= adapter_config[:test_setup_all] %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,18 +8,19 @@ defmodule <%= module %> do | |
timestamps | ||
end | ||
|
||
@required_fields ~w(<%= Enum.map_join(attrs, " ", &elem(&1, 0)) %>) | ||
@optional_fields ~w() | ||
@required_fields [<%= Enum.map_join(attrs, ", ", &inspect(elem(&1, 0))) %>] | ||
@optional_fields [] | ||
|
||
@doc """ | ||
Creates a changeset based on the `model` and `params`. | ||
Creates a changeset based on the `struct` and `params`. | ||
If no params are provided, an invalid changeset is returned | ||
with no validation performed. | ||
""" | ||
def changeset(model, params \\ :empty) do | ||
model | ||
|> cast(params, @required_fields, @optional_fields) | ||
def changeset(struct, params \\ %{}) do | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
josevalim
via email
Member
|
||
struct | ||
|> cast(params, @required_fields ++ @optional_fields) | ||
|> validate_required(@required_fields) | ||
<%= for k <- uniques do %> |> unique_constraint(<%= inspect k %>) | ||
<% end %> end | ||
end |
What do you think about another name instead of struct? Credo isn't happy about that, because its a bit unsafe to use struct (defined in Kernel).