Skip to content

Conversation

@bart-degreed
Copy link
Contributor

I'm not sure if this is a good solution, but at least this removes the crash when trying to create an instance of abstract base class (see #696). There are likely more places we need to change.

var rio = (ResourceIdentifierObject)relationshipData.Data;
var relatedId = rio?.Id;

var resourceContext = relationshipData.SingleData == null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simplified?

var relatedResourceType = relationshipData.SingleData == null
    ? attr.RightType
    : ResourceContextProvider.GetResourceContext(relationshipData.SingleData.Type).ResourceType;

// this does not make sense in the following case: if we're setting the dependent of a one-to-one relationship, IdentifiablePropertyName should be null.
var foreignKeyProperty = resourceProperties.FirstOrDefault(p => p.Name == attr.IdentifiablePropertyName);

if (foreignKeyProperty != null)
    // there is a FK from the current resource pointing to the related object,
    // i.e. we're populating the relationship from the dependent side.
    SetForeignKey(resource, foreignKeyProperty, attr, relatedId, relatedResourceType);

SetNavigation(resource, attr, relatedId, relatedResourceType);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: isn't ResourceContextProvider.GetResourceContext(relationshipData.SingleData.Type).ResourceType; always just equal to relationshipData.SingleData.Type? Because relationshipData.SingleData.Type is parsed from the request body, so if I'm not mistaken this will never equal the abstract base type.

{ // if the relationship is set to null, no need to set the navigation property to null: this is the default value.
var relatedResources = relationshipData.ManyData.Select(rio =>
{
// TODO: [#696] Potential location where we crash if the relationship targets an abstract base class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is valid. I think we'll have to introduce the equivalent approach as for SetHasOneRelationship

/// </summary>
private IIdentifiable ParseIncludedRelationship(RelationshipAttribute relationshipAttr, ResourceIdentifierObject relatedResourceIdentifier)
{
// TODO: [#696] Potential location where we crash if the relationship targets an abstract base class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True


var newLinks = relationshipIds.Select(x =>
{
// TODO: [#696] Potential location where we crash if the relationship targets an abstract base class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. This one seems a bit more difficult to resolve

List<object> throughResources = new List<object>();
foreach (IIdentifiable identifiable in (IEnumerable)newValue)
{
// TODO: [#696] Potential location where we crash if the relationship targets an abstract base class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this one

@maurei
Copy link
Member

maurei commented Sep 18, 2020

Superceded by #833

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants