First the mapping...
<set name="Comments" table="cm_events_venue_comment" inverse="true"
lazy="true" generic="true" cascade="all-delete-orphan"
batch-size="10" order-by="dateCreated ASC">
<cache usage="read-write" />
<key column="venueId" />
<one-to-many class="VenueComment" />
</set>
A passing test..
[Test]
public void CanSaveAndDeleteComments()
{
User u = TestDataHelper.CreateUser("Sir", "Talkalot");
VenueComment comment;
Venue v = GetVenueById();
PerformInTransaction(() =>
{
userRepository.SaveOrUpdate(u);
comment = new VenueComment()
{
Commenter = u,
Text = "I like ifs and buts and i cannot lie..",
DateCreated = DateTime.Now
};
v.AddComment(comment);
comment = new VenueComment()
{
Commenter = u,
Text = "And words ending in 'ly'",
DateCreated = DateTime.Now
};
v.AddComment(comment);
Assert.DoesNotThrow(()=>venueRepository.SaveOrUpdate(v));
});
// Test retrieval
Session.Evict(v);
v = GetVenueById();
v.Comments.Count.ShouldEqual(2);
var c = v.Comments.FirstOrDefault<VenueComment>();
c.Commenter.Id.ShouldEqual(u.Id);
// and deletion
PerformInTransaction(() =>
{
v.RemoveComment(c);
});
Session.Evict(v);
v = GetVenueById();
v.Comments.Count.ShouldEqual(1);
}
My problems comes in the controller of my app :
[Authenticate, AcceptAjax]
public ActionResult DeleteComment(int id)
{
return PerformInTransaction<ActionResult>(() =>
{
var comment = commonDao.GetObjectById<VenueComment>(id);
if (comment == null)
return JsonFailure("Comment not found");
if (comment.Commenter.Id == CurrentUser.Id ||
AuthUtil.IsAdministrator()) //
{
var venue = comment.Venue;
venue.RemoveComment(comment);
return JsonSuccess(id);
}
return JsonFailure("You can only delete comments you created.");
});
}
According to Log4Net, no deletes were issued. As i said the above test passes, so the mapping should be correct...
Any clues ?