Skip to content

Commit

Permalink
fix: Remove flawed logic that chooses the wrong foreign key for navig…
Browse files Browse the repository at this point in the history
…ation properties where the target type of the navigation property has a primary key that also serves as a foreign key in some other relationship. In exceedingly rare cases, you may now have to add a `[ForeignKey(Name = ...)]` attribute to any navigation properties that may now throw a codegen validation error that their foreign key property cannot be discovered automatically. Related to this issue, `ClassViewModel.IsOneToOne` is now deprecated and slated for future removal.
  • Loading branch information
ascott18 committed Oct 1, 2024
1 parent 281c535 commit 513db25
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 5.0.3

- fix: Remove flawed logic that chooses the wrong foreign key for navigation properties where the target type of the navigation property has a primary key that also serves as a foreign key in some other relationship. In exceedingly rare cases, you may now have to add a `[ForeignKey(Name = ...)]` attribute to any navigation properties that may now throw a codegen validation error that their foreign key property cannot be discovered automatically. Related to this issue, `ClassViewModel.IsOneToOne` is now deprecated and slated for future removal.

# 5.0.2

- feat: Make "not found" messages from data sources clearer when the ID is null or empty string. (#447)
Expand Down
1 change: 1 addition & 0 deletions src/IntelliTect.Coalesce/TypeDefinition/ClassViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ public IEnumerable<SearchableProperty> SearchProperties(ClassViewModel? rootMode
ClientProperties.FirstOrDefault(f => f.Name == "Name") ??
PrimaryKey;

[Obsolete("The logic in this property is flawed and does not consider that a single entity can participate in multiple relationships. It will be removed in a future version.")]
public bool IsOneToOne => PrimaryKey?.IsForeignKey ?? false;

#pragma warning disable CS0618 // Type or member is obsolete
Expand Down
4 changes: 0 additions & 4 deletions src/IntelliTect.Coalesce/TypeDefinition/PropertyViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,6 @@ public PropertyViewModel? ForeignKeyProperty
// Use the ForeignKey Attribute on the key property if it is there.
?? EffectiveParent.Properties.SingleOrDefault(p => Name == p.GetAttributeValue<ForeignKeyAttribute>(a => a.Name))?.Name

// See if this is a one-to-one using the parent's key
// Look up the other object and check the key
?? (Object?.IsOneToOne ?? false ? EffectiveParent.PrimaryKey?.Name : null)

// Look for a property that follows convention.
?? Name + ConventionalIdSuffix;

Expand Down

0 comments on commit 513db25

Please sign in to comment.