@sap/cds-compiler
Advanced tools
Comparing version 4.9.2 to 4.9.4
@@ -1296,3 +1296,3 @@ /** @module API */ | ||
function handleTenantDiscriminator( options, internalOptions, messageFunctions ) { | ||
if (options.tenantDiscriminator && options.withHanaAssociations) { | ||
if (options.tenantDiscriminator && options.withHanaAssociations && internalOptions.sqlDialect === 'hana') { | ||
messageFunctions.error('api-invalid-combination', null, { | ||
@@ -1299,0 +1299,0 @@ option: 'tenantDiscriminator', |
@@ -175,2 +175,3 @@ 'use strict'; | ||
const hardOptions = { src: 'hdi', toSql: true, forHana: true }; | ||
// TODO: sqlDialect should be a hard option! | ||
const defaultOptions = { | ||
@@ -183,2 +184,3 @@ sqlMapping: 'plain', sqlDialect: 'hana', generatedByComment: false, withHanaAssociations: true, | ||
const hardOptions = { forHana: true }; | ||
// TODO: sqlDialect should be a hard option! | ||
const defaultOptions = { sqlMapping: 'plain', sqlDialect: 'hana' }; | ||
@@ -185,0 +187,0 @@ return translateOptions(options, defaultOptions, hardOptions, { sqlDialect: generateStringValidator([ 'hana' ]) }, undefined, 'to.hdbcds'); |
@@ -206,24 +206,24 @@ 'use strict'; | ||
const tenantForeignKey = isTenant && dependentKeyValuePair[0] === 'tenant'; | ||
if ($foreignKeyConstraint && (!tenantForeignKey || $foreignKeyConstraint.upLinkFor)) { | ||
if ($foreignKeyConstraint && (!tenantForeignKey || $foreignKeyConstraint.upLinkFor)) | ||
return; | ||
const parentKeyValuePair = parentKeys.pop(); | ||
const parentKeyName = parentKeyValuePair[0]; | ||
const constraint = { | ||
parentKey: parentKeyName, | ||
parentTable, | ||
upLinkFor, | ||
sourceAssociation, | ||
onDelete: upLinkFor ? 'CASCADE' : 'RESTRICT', | ||
validated, | ||
enforced, | ||
}; | ||
if (tenantForeignKey) { | ||
const dontOverwriteUp = dependentKey.$foreignKeyConstraint && dependentKey.$foreignKeyConstraint.some(c => c.sourceAssociation === sourceAssociation && c.parentTable === parentTable); | ||
const dontOverwriteTexts = dependentKey.$foreignKeyConstraint && dependentKey.$foreignKeyConstraint.some(c => c.sourceAssociation === 'texts' && c.upLinkFor.texts); | ||
if (!dontOverwriteUp && !dontOverwriteTexts) | ||
dependentKey.$foreignKeyConstraint = dependentKey.$foreignKeyConstraint ? [ ...dependentKey.$foreignKeyConstraint, constraint ] : [ constraint ]; | ||
} | ||
else if ($foreignKeyConstraint && tenantForeignKey) { | ||
parentKeys.pop(); | ||
$foreignKeyConstraint.sourceAssociation.push(sourceAssociation); | ||
} | ||
else { | ||
const parentKeyValuePair = parentKeys.pop(); | ||
const parentKeyName = parentKeyValuePair[0]; | ||
const constraint = { | ||
parentKey: parentKeyName, | ||
parentTable, | ||
upLinkFor, | ||
sourceAssociation: tenantForeignKey | ||
? [ sourceAssociation ] | ||
: sourceAssociation, | ||
onDelete: upLinkFor ? 'CASCADE' : 'RESTRICT', | ||
validated, | ||
enforced, | ||
}; | ||
dependentKey.$foreignKeyConstraint = constraint; | ||
@@ -513,9 +513,7 @@ } | ||
if (element.$foreignKeyConstraint) { | ||
const $foreignKeyConstraint = Object.assign({}, element.$foreignKeyConstraint); | ||
const tenantConstraints = element.$foreignKeyConstraint; | ||
delete element.$foreignKeyConstraint; | ||
// create a foreign key constraint for the tenant column with each association in the dependent entity | ||
$foreignKeyConstraint.sourceAssociation.forEach((sourceAssociation) => { | ||
const copy = Object.assign({}, $foreignKeyConstraint); | ||
copy.sourceAssociation = sourceAssociation; | ||
createReferentialConstraints(copy, 'tenant'); | ||
// create (multiple) foreign key constraint(s) for the tenant column with each association in the dependent entity | ||
tenantConstraints.forEach((c) => { | ||
createReferentialConstraints(c, 'tenant'); | ||
}); | ||
@@ -522,0 +520,0 @@ } |
{ | ||
"name": "@sap/cds-compiler", | ||
"version": "4.9.2", | ||
"version": "4.9.4", | ||
"description": "CDS (Core Data Services) compiler and backends", | ||
@@ -5,0 +5,0 @@ "homepage": "https://cap.cloud.sap/", |
Sorry, the diff of this file is too big to display
4925533
101115