-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Set writable: :insert for inserted_at field in timestamps() macro #4752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -343,6 +343,35 @@ defmodule Ecto.SchemaTest do | |
| assert InlineEmbeddedSchema.Many.__schema__(:fields) == [:id, :y] | ||
| end | ||
|
|
||
| defmodule TimestampsWritableDefault do | ||
| use Ecto.Schema | ||
|
|
||
| schema "timestamps" do | ||
| timestamps() | ||
| end | ||
| end | ||
|
|
||
| defmodule TimestampsWritableRaise do | ||
| use Ecto.Schema | ||
| @on_writable_violation :raise | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it is currently, the only way to actually change the |
||
|
|
||
| schema "timestamps" do | ||
| timestamps() | ||
| end | ||
| end | ||
|
|
||
| test "timestamps writable" do | ||
| assert TimestampsWritableDefault.__schema__(:insertable_fields) == {[:updated_at, :inserted_at, :id], []} | ||
| assert TimestampsWritableDefault.__schema__(:updatable_fields) == {[:updated_at, :id], [:inserted_at]} | ||
| assert TimestampsWritableDefault.__schema__(:on_writable_violation, :inserted_at) == :nothing | ||
| assert TimestampsWritableDefault.__schema__(:on_writable_violation, :updated_at) == :nothing | ||
|
|
||
| assert TimestampsWritableRaise.__schema__(:insertable_fields) == {[:updated_at, :inserted_at, :id], []} | ||
| assert TimestampsWritableRaise.__schema__(:updatable_fields) == {[:updated_at, :id], [:inserted_at]} | ||
| assert TimestampsWritableRaise.__schema__(:on_writable_violation, :inserted_at) == :raise | ||
| assert TimestampsWritableRaise.__schema__(:on_writable_violation, :updated_at) == :raise | ||
| end | ||
|
|
||
| defmodule TimestampsAutoGen do | ||
| use Ecto.Schema | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this isn't 100% backwards compatible as the behavior will change subtly if you have
@on_writable_violationset towarnorraiseattempts to updatedinserted_atwill warn or raise whereas they previously would be silently ignored, but 🤷♂️To be fully backwards compatible, I guess we would need to not default this and instead allow the user to specify it via an option like
inserted_at_writable