Skip to content

Commit f84ae66

Browse files
committed
Renamed [Relationship()] attribute to [Collection()]
Originally, the `[Relationship()]` attribute was intended to disambiguate references to `Topic.Relationships` and `Topic.IncomingRelationships`. Almost as soon as it was conceived of, however, it was expanded to include e.g. `Topic.Children`, as well as mapped collections (i.e., strongly typed collections with compatible types), and nested topics (a specialized type of `Topic.Children`). Technically, we can argue that all of these are types of relationships. But the name remains ambiguous and unintuitive, since it sounds specific to `Topic.Relationships`. To mitigate that, it's being renamed to `[Collection()]`, which better articulates that it's clarifying the mapping between the source collection and the target collection, independent of whether or not it's a relationship attribute.
1 parent 8b9ae46 commit f84ae66

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

OnTopic.Tests/BindingModels/InvalidRelationshipTypeTopicBindingModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class InvalidRelationshipTypeTopicBindingModel : BasicTopicBindingModel {
2525

2626
public InvalidRelationshipTypeTopicBindingModel(string? key = null) : base(key, "ContentTypeDescriptor") { }
2727

28-
[Relationship(RelationshipType.NestedTopics)]
28+
[Collection(RelationshipType.NestedTopics)]
2929
public Collection<RelatedTopicBindingModel> ContentTypes { get; } = new();
3030

3131
} //Class

OnTopic.Tests/TopicMappingServiceTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,11 @@ public async Task Map_Relationships_SkipsDisabled() {
384384
\-------------------------------------------------------------------------------------------------------------------------*/
385385
/// <summary>
386386
/// Establishes a <see cref="TopicMappingService"/> and tests whether it successfully derives values from the key and
387-
/// type specified by <see cref="Mapping.Annotations.RelationshipAttribute"/>.
387+
/// type specified by <see cref="Mapping.Annotations.CollectionAttribute"/>.
388388
/// </summary>
389389
/// <remarks>
390390
/// The <see cref="AmbiguousRelationTopicViewModel.RelationshipAlias"/> uses <see
391-
/// cref="Mapping.Annotations.RelationshipAttribute"/> to set the relationship key to <c>AmbiguousRelationship</c> and the
391+
/// cref="Mapping.Annotations.CollectionAttribute"/> to set the relationship key to <c>AmbiguousRelationship</c> and the
392392
/// <see cref="RelationshipType"/> to <see cref="RelationshipType.IncomingRelationship"/>. <c>AmbiguousRelationship</c>
393393
/// refers to a relationship that is both outgoing and incoming. It should be smart enough to a) look for the
394394
/// <c>AmbigousRelationship</c> instead of the <c>RelationshipAlias</c>, and b) source from the <see

OnTopic.Tests/ViewModels/AmbiguousRelationTopicViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace OnTopic.Tests.ViewModels {
1616
/// </summary>
1717
/// <remarks>
1818
/// <para>
19-
/// The <see cref="RelationshipAlias"/> uses <see cref="RelationshipAttribute"/> to set the relationship key to
19+
/// The <see cref="RelationshipAlias"/> uses <see cref="CollectionAttribute"/> to set the relationship key to
2020
/// <c>AmbiguousRelationship</c> and the <see cref="RelationshipType"/> to <see
2121
/// cref="RelationshipType.IncomingRelationship"/>. <c>AmbiguousRelationship</c> refers to a relationship that is both
2222
/// outgoing and incoming.
@@ -27,7 +27,7 @@ namespace OnTopic.Tests.ViewModels {
2727
/// </remarks>
2828
public class AmbiguousRelationTopicViewModel: KeyOnlyTopicViewModel {
2929

30-
[Relationship("AmbiguousRelationship", Type=RelationshipType.IncomingRelationship)]
30+
[Collection("AmbiguousRelationship", Type=RelationshipType.IncomingRelationship)]
3131
public Collection<KeyOnlyTopicViewModel> RelationshipAlias { get; } = new();
3232

3333
} //Class

OnTopic.Tests/ViewModels/Metadata/ContentTypeDescriptorTopicViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class ContentTypeDescriptorTopicViewModel {
2222

2323
public Collection<AttributeDescriptorTopicViewModel> AttributeDescriptors { get; } = new();
2424

25-
[Relationship(RelationshipType.MappedCollection)]
25+
[Collection(RelationshipType.MappedCollection)]
2626
[Follow(Relationships.None)]
2727
public Collection<ContentTypeDescriptorTopicViewModel> PermittedContentTypes { get; } = new();
2828

OnTopic/Mapping/Annotations/RelationshipAttribute.cs renamed to OnTopic/Mapping/Annotations/CollectionAttribute.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace OnTopic.Mapping.Annotations {
88

99
/*============================================================================================================================
10-
| ATTRIBUTE: RELATIONSHIP
10+
| ATTRIBUTE: COLLECTION
1111
\---------------------------------------------------------------------------------------------------------------------------*/
1212
/// <summary>
1313
/// Provides the <see cref="ITopicMappingService"/> with instructions as to which key to follow for the relationship.
@@ -21,32 +21,32 @@ namespace OnTopic.Mapping.Annotations {
2121
/// </para>
2222
/// <para>
2323
/// This attribute instructs the <see cref="ITopicMappingService"/> to instead look for a specified key. This allows the
24-
/// target property name to be decoupled from the source's relationship key. In addition, this attribute can be used to
25-
/// specify the type of relationship expected, which is useful if there might be ambiguity between relationship names (for
26-
/// example, if there is a <see cref="Topic.Relationships"/> with the same key as an <see
27-
/// cref="Topic.IncomingRelationships"/>).
24+
/// target property name to be decoupled from the source's collection key. In addition, this attribute can be used to
25+
/// specify the type of collection expected, which is useful if there might be ambiguity between collection names (for
26+
/// example, if there is a <see cref="Topic.Relationships"/> with the same key as an <see cref="Topic.
27+
/// IncomingRelationships"/>), which is not an uncommon scenario.
2828
/// </para>
2929
/// </remarks>
3030
[System.AttributeUsage(System.AttributeTargets.Property)]
31-
public sealed class RelationshipAttribute : System.Attribute {
31+
public sealed class CollectionAttribute : System.Attribute {
3232

3333
/*==========================================================================================================================
3434
| CONSTRUCTOR
3535
\-------------------------------------------------------------------------------------------------------------------------*/
3636
/// <summary>
37-
/// Annotates a property with the <see cref="RelationshipAttribute"/> by providing an <paramref name="key"/>.
37+
/// Annotates a property with the <see cref="CollectionAttribute"/> by providing an <paramref name="key"/>.
3838
/// </summary>
3939
/// <param name="key">The key value of the relationships associated with the current property.</param>
40-
public RelationshipAttribute(string key) {
40+
public CollectionAttribute(string key) {
4141
TopicFactory.ValidateKey(key, false);
4242
Key = key;
4343
}
4444

4545
/// <summary>
46-
/// Annotates a property with the <see cref="RelationshipAttribute"/> by providing the <see cref="RelationshipType"/>.
46+
/// Annotates a property with the <see cref="CollectionAttribute"/> by providing the <see cref="RelationshipType"/>.
4747
/// </summary>
4848
/// <param name="type">Optional. The type of collection the relationship is associated with.</param>
49-
public RelationshipAttribute(RelationshipType type = RelationshipType.Any) {
49+
public CollectionAttribute(RelationshipType type = RelationshipType.Any) {
5050
Type = type;
5151
}
5252

OnTopic/Mapping/Internal/PropertyConfiguration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public PropertyConfiguration(PropertyInfo property, string? attributePrefix = ""
9292
/*------------------------------------------------------------------------------------------------------------------------
9393
| Attributes: Determine relationship key and type
9494
\-----------------------------------------------------------------------------------------------------------------------*/
95-
GetAttributeValue<RelationshipAttribute>(
95+
GetAttributeValue<CollectionAttribute>(
9696
property,
9797
a => {
9898
RelationshipKey = a.Key ?? RelationshipKey;
@@ -248,7 +248,7 @@ public PropertyConfiguration(PropertyInfo property, string? attributePrefix = ""
248248
/// the DTO to be aliased to a different collection name on the source <see cref="Topic"/>.
249249
/// </para>
250250
/// <para>
251-
/// The <see cref="RelationshipKey"/> property corresponds to the <see cref="RelationshipAttribute.Key"/> property. It
251+
/// The <see cref="RelationshipKey"/> property corresponds to the <see cref="CollectionAttribute.Key"/> property. It
252252
/// can be assigned by decorating a DTO property with e.g. <c>[Relationship("AlternateRelationshipKey")]</c>.
253253
/// </para>
254254
/// </remarks>
@@ -269,7 +269,7 @@ public PropertyConfiguration(PropertyInfo property, string? attributePrefix = ""
269269
/// be ambiguous between multiple collections.
270270
/// </para>
271271
/// <para>
272-
/// The <see cref="RelationshipType"/> property corresponds to the <see cref="RelationshipAttribute.Type"/> property. It
272+
/// The <see cref="RelationshipType"/> property corresponds to the <see cref="CollectionAttribute.Type"/> property. It
273273
/// can be assigned by decorating a DTO property with e.g. <c>[Relationship("AlternateRelationshipKey",
274274
/// RelationshipType.Children)]</c>.
275275
/// </para>

OnTopic/Mapping/Reverse/IReverseTopicMappingService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace OnTopic.Mapping.Reverse {
3636
/// Despite the differences between the <see cref="ITopicMappingService"/> and <see cref="IReverseTopicMappingService"/>s,
3737
/// many attributes are able to be reused between them. For instance, the <see cref="AttributeKeyAttribute"/> can still
3838
/// map a property on a binding model to an attribute of a different name on a <see cref="Topic"/>, just as the <see
39-
/// cref="RelationshipAttribute"/> can with relationships. Other attributes, however, provde no benefit in the reverse
39+
/// cref="CollectionAttribute"/> can with relationships. Other attributes, however, provde no benefit in the reverse
4040
/// scenario, such as <see cref="FlattenAttribute"/> or <see cref="FilterByAttributeAttribute"/>, which really only make
4141
/// sense in creating a "produced view" that is a subset of the original model. That is valuable when creating a view
4242
/// model, but isn't a useful use case when working with binding models.

0 commit comments

Comments
 (0)