Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
feat(core): delete support in persistCascade for 1-to-1 relations #42
Browse files Browse the repository at this point in the history
  • Loading branch information
michiel committed Jul 23, 2019
1 parent e9aca6f commit 03e0281
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/core/src/Resource/Change/Relation/Relation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import flatten from 'lodash/flatten';
import isEmpty from 'lodash/isEmpty';
import isEqual from 'lodash/isEqual';
import { previousState } from '../../../State/State';
import { resourceIsNew } from '../Inspection';
import { resourceHasChanged, resourceIsNew } from '../Inspection';

/**
* @param {HyralResource} resource
Expand Down Expand Up @@ -47,12 +47,12 @@ export function getChangedResourceRelations(resource) {
return [];
}

if (!resourceIsNew(resource) && previousState(resource.stateStack) === null) {
return [];
if (resourceIsNew(resource)) {
return Object.keys(resource.relationships);
}

if (resourceIsNew(resource) && previousState(resource.stateStack) === null) {
return Object.keys(resource.relationships);
if (!resourceHasChanged(resource)) {
return [];
}

return Object.keys(resource.relationships).filter(relation => !isEqual(
Expand All @@ -75,7 +75,11 @@ export function getDeletedOneToOneRelatedResources(resource) {
return [];
}

if (resourceIsNew(resource) || previousState(resource.stateStack) === null) {
if (resourceIsNew(resource)) {
return [];
}

if (!resourceHasChanged(resource)) {
return [];
}

Expand Down

0 comments on commit 03e0281

Please sign in to comment.