Skip to content

Commit e4c6e16

Browse files
committed
Fix combining cascades
Fixes #472 +semver:fix
1 parent 3b66ce6 commit e4c6e16

9 files changed

+67
-13
lines changed

src/FluentNHibernate.Testing/FluentInterfaceTests/AnyMutablePropertyModelGenerationTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ public void CascadeSetsModelCascadePropertyToValue()
3333
.ModelShouldMatch(x => x.Cascade.ShouldEqual("all"));
3434
}
3535

36+
[Test]
37+
public void CascadeAppendModelCascadePropertyToValue()
38+
{
39+
Any<SecondMappedObject>()
40+
.Mapping(m => m
41+
.IdentityType<int>()
42+
.EntityIdentifierColumn("col")
43+
.EntityTypeColumn("col2")
44+
.Cascade.Merge().Cascade.SaveUpdate())
45+
.ModelShouldMatch(x => x.Cascade.ShouldEqual("merge,save-update"));
46+
}
47+
3648
[Test]
3749
public void IdentityTypeSetsModelIdTypePropertyToPropertyTypeName()
3850
{

src/FluentNHibernate.Testing/FluentInterfaceTests/HibernateMappingMutablePropertyModelGenerationTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ public void DefaultCascadeShouldSetModelDefaultCascadePropertyToValue()
3737
.ModelShouldMatch(x => x.DefaultCascade.ShouldEqual("all"));
3838
}
3939

40+
[Test]
41+
public void DefaultCascadeShouldAppendModelDefaultCascadePropertyToValue()
42+
{
43+
HibernateMapping()
44+
.Mapping(m => { m.DefaultCascade.Merge(); m.DefaultCascade.SaveUpdate(); })
45+
.ModelShouldMatch(x => x.DefaultCascade.ShouldEqual("merge,save-update"));
46+
}
47+
4048
[Test]
4149
public void DefaultLazyShouldSetModelDefaultLazyPropertyToTrue()
4250
{

src/FluentNHibernate.Testing/FluentInterfaceTests/ManyToManyMutablePropertyModelGenerationTests.cs

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

55+
[Test]
56+
public void CascadeShouldAppendModelCascadePropertyToValue()
57+
{
58+
ManyToMany(x => x.BagOfChildren)
59+
.Mapping(m => { m.Cascade.SaveUpdate(); m.Cascade.Merge(); })
60+
.ModelShouldMatch(x => x.Cascade.ShouldEqual("save-update,merge"));
61+
}
62+
5563
[Test]
5664
public void CollectionTypeShouldSetModelCollectionTypePropertyToValue()
5765
{

src/FluentNHibernate.Testing/FluentInterfaceTests/OneToOneMutablePropertyModelGenerationTests.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,37 @@ public void ClassShouldSetModelClassPropertyToValue()
3333
}
3434

3535
[Test]
36-
public void CascadeShouldSetModelCascadePropertyToTrue()
36+
public void ConstrainedShouldSetModelConstrainedPropertyToTrue()
3737
{
3838
OneToOne()
3939
.Mapping(m => m.Constrained())
4040
.ModelShouldMatch(x => x.Constrained.ShouldBeTrue());
4141
}
4242

4343
[Test]
44-
public void NotCascadeShouldSetModelCascadePropertyToFalse()
44+
public void NotConstrainedShouldSetModelConstrainedPropertyToFalse()
4545
{
4646
OneToOne()
4747
.Mapping(m => m.Not.Constrained())
4848
.ModelShouldMatch(x => x.Constrained.ShouldBeFalse());
4949
}
5050

51+
[Test]
52+
public void CascadeSetsModelCascadePropertyToValue()
53+
{
54+
OneToOne()
55+
.Mapping(m => m.Cascade.All())
56+
.ModelShouldMatch(x => x.Cascade.ShouldEqual("all"));
57+
}
58+
59+
[Test]
60+
public void CascadeAppendModelCascadePropertyToValue()
61+
{
62+
OneToOne()
63+
.Mapping(m => { m.Cascade.Merge(); m.Cascade.SaveUpdate(); })
64+
.ModelShouldMatch(x => x.Cascade.ShouldEqual("merge,save-update"));
65+
}
66+
5167
[Test]
5268
public void FetchShouldSetModelFetchPropertyToValue()
5369
{

src/FluentNHibernate/Mapping/AnyPart.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ public AnyPart(Type entity, Member member)
3131
this.entity = entity;
3232
this.member = member;
3333
access = new AccessStrategyBuilder<AnyPart<T>>(this, value => attributes.Set("Access", Layer.UserSupplied, value));
34-
cascade = new CascadeExpression<AnyPart<T>>(this, value => attributes.Set("Cascade", Layer.UserSupplied, value));
34+
cascade = new CascadeExpression<AnyPart<T>>(this, value =>
35+
{
36+
var current = attributes.Get("Cascade") as string;
37+
attributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
38+
});
3539

3640
SetDefaultAccess();
3741
}

src/FluentNHibernate/Mapping/HibernateMappingPart.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ public class HibernateMappingPart : IHibernateMappingProvider
1313

1414
public HibernateMappingPart()
1515
{
16-
defaultCascade = new CascadeExpression<HibernateMappingPart>(this, value => attributes.Set("DefaultCascade", Layer.UserSupplied, value));
16+
defaultCascade = new CascadeExpression<HibernateMappingPart>(this, value =>
17+
{
18+
var current = attributes.Get("DefaultCascade") as string;
19+
attributes.Set("DefaultCascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
20+
});
1721
defaultAccess = new AccessStrategyBuilder<HibernateMappingPart>(this, value => attributes.Set("DefaultAccess", Layer.UserSupplied, value));
1822
}
1923

src/FluentNHibernate/Mapping/OneToManyPart.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class OneToManyPart<TChild> : ToManyBase<OneToManyPart<TChild>, TChild>
1212
{
1313
private readonly Type entity;
1414
private readonly ColumnMappingCollection<OneToManyPart<TChild>> keyColumns;
15-
private readonly CollectionCascadeExpression<OneToManyPart<TChild>> cascade;
1615
private readonly NotFoundExpression<OneToManyPart<TChild>> notFound;
1716
private IndexManyToManyPart manyToManyIndex;
1817
private readonly Type childType;
@@ -31,11 +30,6 @@ protected OneToManyPart(Type entity, Member member, Type collectionType)
3130
childType = collectionType;
3231

3332
keyColumns = new ColumnMappingCollection<OneToManyPart<TChild>>(this);
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-
});
3933
notFound = new NotFoundExpression<OneToManyPart<TChild>>(this, value => relationshipAttributes.Set("NotFound", Layer.UserSupplied, value));
4034

4135
collectionAttributes.Set("Name", Layer.Defaults, member.Name);
@@ -54,7 +48,7 @@ public NotFoundExpression<OneToManyPart<TChild>> NotFound
5448
/// </summary>
5549
public new CollectionCascadeExpression<OneToManyPart<TChild>> Cascade
5650
{
57-
get { return cascade; }
51+
get { return base.Cascade; }
5852
}
5953

6054
/// <summary>

src/FluentNHibernate/Mapping/OneToOnePart.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ public OneToOnePart(Type entity, Member member)
2121
{
2222
access = new AccessStrategyBuilder<OneToOnePart<TOther>>(this, value => attributes.Set("Access", Layer.UserSupplied, value));
2323
fetch = new FetchTypeExpression<OneToOnePart<TOther>>(this, value => attributes.Set("Fetch", Layer.UserSupplied, value));
24-
cascade = new CascadeExpression<OneToOnePart<TOther>>(this, value => attributes.Set("Cascade", Layer.UserSupplied, value));
24+
cascade = new CascadeExpression<OneToOnePart<TOther>>(this, value =>
25+
{
26+
var current = attributes.Get("Cascade") as string;
27+
attributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
28+
});
2529
this.entity = entity;
2630
this.member = member;
2731

src/FluentNHibernate/Mapping/ToManyBase.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ protected ToManyBase(Type entity, Member member, Type type)
3636
AsBag();
3737
access = new AccessStrategyBuilder<T>((T)this, value => collectionAttributes.Set("Access", Layer.UserSupplied, value));
3838
fetch = new FetchTypeExpression<T>((T)this, value => collectionAttributes.Set("Fetch", Layer.UserSupplied, value));
39-
cascade = new CollectionCascadeExpression<T>((T)this, value => collectionAttributes.Set("Cascade", Layer.UserSupplied, value));
39+
cascade = new CollectionCascadeExpression<T>((T)this, value =>
40+
{
41+
var current = collectionAttributes.Get("Cascade") as string;
42+
collectionAttributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
43+
});
4044

4145
SetDefaultCollectionType();
4246
SetCustomCollectionType(type);

0 commit comments

Comments
 (0)