Skip to content

Commit b111532

Browse files
committed
Merge pull request #1 from degert/master
Quick fix for #123: Append cascade options instead of overwriting.
2 parents 754cce8 + 7dbcb7b commit b111532

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/FluentNHibernate.Testing/FluentInterfaceTests/ManyToOneMutablePropertyModelGenerationTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ public void CascadeShouldSetModelCascadePropertyToValue()
2525
.ModelShouldMatch(x => x.Cascade.ShouldEqual("all"));
2626
}
2727

28+
[Test]
29+
public void CascadeShouldAppendModelCascadePropertyToValue()
30+
{
31+
ManyToOne()
32+
.Mapping(m => { m.Cascade.SaveUpdate(); m.Cascade.Merge(); })
33+
.ModelShouldMatch(x => x.Cascade.ShouldEqual("save-update,merge"));
34+
}
35+
2836
[Test]
2937
public void ShouldSetModelClassPropertyToPropertyType()
3038
{

src/FluentNHibernate.Testing/FluentInterfaceTests/OneToManyMutablePropertyModelGenerationTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ public void CascadeShouldSetModelCascadePropertyToValue()
4545
.ModelShouldMatch(x => x.Cascade.ShouldEqual("all"));
4646
}
4747

48+
[Test]
49+
public void CascadeShouldAppendModelCascadePropertyToValue()
50+
{
51+
OneToMany(x => x.BagOfChildren)
52+
.Mapping(m => { m.Cascade.SaveUpdate(); m.Cascade.Merge(); })
53+
.ModelShouldMatch(x => x.Cascade.ShouldEqual("save-update,merge"));
54+
}
55+
4856
[Test]
4957
public void CollectionTypeShouldSetModelCollectionTypePropertyToValue()
5058
{

src/FluentNHibernate/Mapping/ManyToOnePart.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ public ManyToOnePart(Type entity, Member member)
2727
this.member = member;
2828
access = new AccessStrategyBuilder<ManyToOnePart<TOther>>(this, value => attributes.Set("Access", Layer.UserSupplied, value));
2929
fetch = new FetchTypeExpression<ManyToOnePart<TOther>>(this, value => attributes.Set("Fetch", Layer.UserSupplied, value));
30-
cascade = new CascadeExpression<ManyToOnePart<TOther>>(this, value => attributes.Set("Cascade", Layer.UserSupplied, value));
30+
cascade = new CascadeExpression<ManyToOnePart<TOther>>(this, value =>
31+
{
32+
var current = attributes.Get("Cascade") as string;
33+
attributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
34+
});
3135
notFound = new NotFoundExpression<ManyToOnePart<TOther>>(this, value => attributes.Set("NotFound", Layer.UserSupplied, value));
3236

3337
SetDefaultAccess();

src/FluentNHibernate/Mapping/OneToManyPart.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ protected OneToManyPart(Type entity, Member member, Type collectionType)
3131
childType = collectionType;
3232

3333
keyColumns = new ColumnMappingCollection<OneToManyPart<TChild>>(this);
34-
cascade = new CollectionCascadeExpression<OneToManyPart<TChild>>(this, value => collectionAttributes.Set("Cascade", Layer.UserSupplied, value));
34+
cascade = new CollectionCascadeExpression<OneToManyPart<TChild>>(this, value =>
35+
{
36+
var current = collectionAttributes.Get("Cascade") as string;
37+
collectionAttributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
38+
});
3539
notFound = new NotFoundExpression<OneToManyPart<TChild>>(this, value => relationshipAttributes.Set("NotFound", Layer.UserSupplied, value));
3640

3741
collectionAttributes.Set("Name", Layer.Defaults, member.Name);

0 commit comments

Comments
 (0)