Skip to content

Commit 3816296

Browse files
committed
Revert "Add support for :writable option on belongs_to (#4624)"
This reverts commit 576665f.
1 parent 59d21ee commit 3816296

2 files changed

Lines changed: 0 additions & 41 deletions

File tree

lib/ecto/schema.ex

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,12 +1106,6 @@ defmodule Ecto.Schema do
11061106
* `:where` - A filter for the association. See "Filtering associations"
11071107
in `has_many/3`.
11081108
1109-
* `:writable` - Defines when the underlying field is allowed to modified, Must be
1110-
one of `:always`, `:insert`, or `:never`. If set to `:always`, the field can be
1111-
modified by any repo operation. If set to `:insert`, the field can be inserted
1112-
but cannot be further modified, even in an upsert. If set to `:never`, the field
1113-
becomes read only. Defaults to `:always`.
1114-
11151109
## Examples
11161110
11171111
defmodule Comment do
@@ -2144,7 +2138,6 @@ defmodule Ecto.Schema do
21442138
:defaults,
21452139
:primary_key,
21462140
:source,
2147-
:writable,
21482141
:where
21492142
]
21502143

test/ecto/repo/belongs_to_test.exs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ defmodule Ecto.Repo.BelongsToTest do
3535
end
3636
end
3737

38-
defmodule RestrictedSchema do
39-
use Ecto.Schema
40-
41-
schema "restricted_schema" do
42-
belongs_to :unwritable, MyAssoc, writable: :never
43-
belongs_to :non_updatable, MyAssoc, writable: :insert
44-
end
45-
end
46-
4738
test "handles assocs on insert" do
4839
sample = %MyAssoc{x: "xyz"}
4940

@@ -505,29 +496,4 @@ defmodule Ecto.Repo.BelongsToTest do
505496
assert updated_schema.assoc_id == 2
506497
assert %Ecto.Association.NotLoaded{} = updated_schema.assoc
507498
end
508-
509-
test "handles writable: :never" do
510-
schema =
511-
%RestrictedSchema{}
512-
|> Ecto.Changeset.cast(%{unwritable_id: 111}, [:unwritable_id])
513-
|> TestRepo.insert!()
514-
515-
assert schema.unwritable_id == nil
516-
end
517-
518-
test "handles writable: :insert" do
519-
schema =
520-
%RestrictedSchema{}
521-
|> Ecto.Changeset.cast(%{non_updatable_id: 222}, [:non_updatable_id])
522-
|> TestRepo.insert!()
523-
524-
assert schema.non_updatable_id == 222
525-
526-
schema =
527-
schema
528-
|> Ecto.Changeset.cast(%{non_updatable_id: 333}, [:non_updatable_id])
529-
|> TestRepo.update!()
530-
531-
assert schema.non_updatable_id == 222
532-
end
533499
end

0 commit comments

Comments
 (0)