Skip to content

Commit a57246f

Browse files
committed
Fixes #81 (and adds test to verify)
1 parent 78b294e commit a57246f

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

Postgrest/PostgrestContractResolver.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,7 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ
9292
? referenceAttr.TableName
9393
: referenceAttr.ColumnName;
9494

95-
if (IsInsert && referenceAttr.IgnoreOnInsert)
96-
prop.Ignored = true;
97-
98-
if (IsUpdate && referenceAttr.IgnoreOnUpdate)
99-
prop.Ignored = true;
100-
101-
if ((IsUpsert && referenceAttr.IgnoreOnUpdate) || (IsUpsert && referenceAttr.IgnoreOnInsert))
95+
if (IsInsert || IsUpdate)
10296
prop.Ignored = true;
10397

10498
return prop;

PostgrestTests/ReferenceTests.cs

+31-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public async Task TestModelCanReferenceSameForeignTableMultipleTimes()
108108
Assert.IsInstanceOfType(response.Model!.MovieFK2, typeof(Movie));
109109
Assert.IsInstanceOfType(response.Model!.RandomPersonFK, typeof(Person));
110110
}
111-
111+
112112
[TestMethod("Reference: Table can reference a nested model with the same foreign table multiple times.")]
113113
public async Task TestModelCanReferenceNestedModelWithSameForeignTableMultipleTimes()
114114
{
@@ -120,5 +120,35 @@ public async Task TestModelCanReferenceNestedModelWithSameForeignTableMultipleTi
120120
Assert.IsInstanceOfType(response.Model!.User, typeof(User));
121121
Assert.IsInstanceOfType(response.Model!.FKTestModel, typeof(ForeignKeyTestModel));
122122
}
123+
124+
[TestMethod("Reference: Model inserts and updates (ignoring reference properties) when Reference is not null.")]
125+
public async Task TestModelInsertsAndUpdatesWhenReferenceIsSpecified()
126+
{
127+
var client = new Client(BaseUrl);
128+
129+
var newModel = new Movie()
130+
{
131+
Name = "The Blue Eyed Samurai (Movie)",
132+
Status = MovieStatus.OffDisplay,
133+
People =
134+
[
135+
new Person { FirstName = "Maya", LastName = "Erskine" },
136+
new Person { FirstName = "Masi", LastName = "Oka" }
137+
]
138+
};
139+
140+
var insertedModel = await client.Table<Movie>().Insert(newModel);
141+
142+
Assert.IsNotNull(insertedModel.Model);
143+
Assert.IsNotNull(insertedModel.Model.Name);
144+
Assert.AreEqual(MovieStatus.OffDisplay, insertedModel.Model.Status);
145+
146+
insertedModel.Model.Status = MovieStatus.OnDisplay;
147+
148+
var updatedModel = await insertedModel.Model.Update<Movie>();
149+
150+
Assert.IsNotNull(updatedModel.Model);
151+
Assert.AreEqual(MovieStatus.OnDisplay, updatedModel.Model.Status);
152+
}
123153
}
124154
}

0 commit comments

Comments
 (0)