Skip to content

Commit bda9e19

Browse files
committed
Merge pull request #99 from MaciejSzczepanski/master
Fixed Formula with ManyToOne
2 parents 4c7424a + 783638b commit bda9e19

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/FluentNHibernate.Testing/DomainModel/Mapping/ManyToOneTester.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,18 @@ public void LazyLoadResetsNotValue()
162162
.Not.LazyLoad().Not.Nullable())
163163
.Element("class/many-to-one/column").HasAttribute("not-null", "true");
164164
}
165+
166+
[Test]
167+
public void ManyToOneFormulaShouldSetFormulaAndNotRenderColumn()
168+
{
169+
new MappingTester<MappedObject>()
170+
.ForMapping(map =>
171+
{
172+
map.References(x => x.Parent)
173+
.Formula("foo(bar)");
174+
})
175+
.Element("class/many-to-one").HasAttribute("formula", "foo(bar)")
176+
.Element("class/many-to-one/column").DoesntExist();
177+
}
165178
}
166179
}

src/FluentNHibernate/Mapping/ManyToOnePart.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ ManyToOneMapping IManyToOneMappingProvider.GetManyToOneMapping()
353353
mapping.Set(x => x.Name, Layer.Defaults, member.Name);
354354
mapping.Set(x => x.Class, Layer.Defaults, new TypeReference(typeof(TOther)));
355355

356-
if (columns.Count == 0)
356+
if (columns.Count == 0 && !mapping.IsSpecified("Formula"))
357357
mapping.AddColumn(Layer.Defaults, CreateColumn(member.Name + "_id"));
358358

359359
foreach (var column in columns)

0 commit comments

Comments
 (0)