Skip to content

Commit

Permalink
Added support for ChildWhere and ChildOrderBy on many-to-many mapping…
Browse files Browse the repository at this point in the history
…s to be set via conventions
  • Loading branch information
paulbatum committed Jun 19, 2010
1 parent 8294f2a commit 4c96c43
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ public void ShouldSetChildForeignKeyProperty()

VerifyModel(x => ((ManyToManyMapping)x.Relationship).ForeignKey.ShouldEqual("xxx"));
}

[Test]
public void ShouldSetRelationshipWhereProperty()
{
Convention(x => x.Relationship.Where("where clause"));

VerifyModel(x => ((ManyToManyMapping)x.Relationship).Where.ShouldEqual("where clause"));
}

[Test]
public void ShouldSetOrderByProperty()
{
Convention(x => x.Relationship.OrderBy("order clause"));

VerifyModel(x => ((ManyToManyMapping)x.Relationship).OrderBy.ShouldEqual("order clause"));
}

#region Helpers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ public interface IManyToManyInspector : IRelationshipInspector
bool LazyLoad { get; }
NotFound NotFound { get; }
Type ParentType { get; }

/// <summary>
/// Applies to the joining table for this many-to-many.
/// </summary>
string Where { get; }

/// <summary>
/// Applies to the joining table for this many-to-many.
/// </summary>
string OrderBy { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,9 @@ public string Where
get { return mapping.Where; }
}

}
public string OrderBy
{
get { return mapping.OrderBy; }
}
}
}
10 changes: 10 additions & 0 deletions src/FluentNHibernate/Conventions/Instances/IManyToManyInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,15 @@ public interface IManyToManyInstance : IManyToManyInspector, IRelationshipInstan
void Column(string columnName);
new IDefaultableEnumerable<IColumnInstance> Columns { get; }
new void ForeignKey(string constraint);

/// <summary>
/// Applies to the joining table for this many-to-many.
/// </summary>
new void Where(string where);

/// <summary>
/// Applies to the joining table for this many-to-many.
/// </summary>
new void OrderBy(string orderBy);
}
}
14 changes: 13 additions & 1 deletion src/FluentNHibernate/Conventions/Instances/ManyToManyInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,20 @@ public void CustomClass(Type type)

public new void ForeignKey(string constraint)
{
if (!mapping.IsSpecified("ForeignKey"))
if (!mapping.IsSpecified(x => x.ForeignKey))
mapping.ForeignKey = constraint;
}

public new void Where(string where)
{
if (!mapping.IsSpecified(x => x.Where))
mapping.Where = where;
}

public new void OrderBy(string orderBy)
{
if (!mapping.IsSpecified(x => x.OrderBy))
mapping.OrderBy = orderBy;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ public override bool IsSpecified(string property)
return attributes.IsSpecified(property);
}

public bool IsSpecified<TResult>(Expression<Func<ManyToManyMapping, TResult>> property)
{
return attributes.IsSpecified(property);
}

public bool HasValue<TResult>(Expression<Func<ManyToManyMapping, TResult>> property)
{
return attributes.HasValue(property);
Expand Down

0 comments on commit 4c96c43

Please sign in to comment.