File tree 2 files changed +10
-1
lines changed 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -1300,10 +1300,17 @@ defmodule Ecto.Integration.RepoTest do
1300
1300
end
1301
1301
1302
1302
test "virtual field" do
1303
- assert % Post { id: id } = TestRepo . insert! ( % Post { title: "1" } )
1303
+ assert % Post { id: id } = TestRepo . insert! ( % Post { title: "1" , temp: "special" } )
1304
1304
assert TestRepo . get ( Post , id ) . temp == "temp"
1305
1305
end
1306
1306
1307
+ test "virtual embed" do
1308
+ assert % Order { id: id , last_seen_item: % Item { reference: "1" } } =
1309
+ TestRepo . insert! ( % Order { last_seen_item: % Item { reference: "1" } } )
1310
+
1311
+ assert % { last_seen_item: nil } = TestRepo . get ( Order , id )
1312
+ end
1313
+
1307
1314
## Query syntax
1308
1315
1309
1316
defmodule Foo do
Original file line number Diff line number Diff line change @@ -266,13 +266,15 @@ defmodule Ecto.Integration.Order do
266
266
* Embedding one schema
267
267
* Preloading items inside embeds_many
268
268
* Preloading items inside embeds_one
269
+ * Virtual embeds
269
270
* Field source with json_extract_path
270
271
271
272
"""
272
273
use Ecto.Integration.Schema
273
274
274
275
schema "orders" do
275
276
field :metadata , :map , source: :meta
277
+ embeds_one :last_seen_item , Ecto.Integration.Item , virtual: true
276
278
embeds_one :item , Ecto.Integration.Item
277
279
embeds_many :items , Ecto.Integration.Item
278
280
belongs_to :permalink , Ecto.Integration.Permalink
You can’t perform that action at this time.
0 commit comments