Optional vs Mandatory reference

I am trying to retrieve the conservation rate that is found within the Currencies collection. Can anybody help me with the solution. Both attempts below cause the corresponding syntax errors.

'Currency': text ~> ^ ^ .'Relationship Management'.'Currencies'[] = >'Customer'.'Invoicing'.'Currency'
'Conversion rate': number '10^-3 currency/euro' = >'Currency'.'Current Rate'

>'Currency' causes:
narrowing constraint violation for ‘existence’:
(1, 1): - expected: ‘existence’ of type ‘mandatory’
(1, 1): - but found: ‘existence’ of type ‘optional’

'Currency': text -> ^ ^ .'Relationship Management'.'Currencies'[] = >'Customer'.'Invoicing'.'Currency'
'Conversion rate': number '10^-3 currency/euro' = >'Currency'.'Current Rate'

-> causes"
no valid ‘value’ found for ‘path’. Unexpected ‘value object’:
application.alan(11477, 73): - expected: ‘node’
application.alan(9288, 16): - but found: ‘leaf’
application.alan(9288, 16): defined by .‘Customers’.‘Invoicing’.‘Currency’ of type ‘application’!‘node’.‘attributes’.‘type’?‘property’

Thank you in advance! I appreciate all the tips :slight_smile:

The error from your first example is because when using an optional reference (~>) no value may be available, in which case a Conversion rate cannot be computed. You have to handle that case explicitly:

'Conversion rate': number '10^-3 currency/euro' = switch >'Currency' (
  | node as $'curr' => $'curr'.'Current Rate'
  | none => 1 // or whatever fallback value you want
)

As for the second example: when deriving a mandatory reference, your expression needs to produce a node at runtime. I.e. not a text value. So, you need this:

'Currency': text -> ^ ^ .'Relationship Management'.'Currencies'[] = >'Customer'.'Invoicing'>'Currency'

Note that I changed the . to > before Currency in the derivation expression (= <derivation expression>).

1 Like

I think it would be ok to make this a mandatory reference (->), Martinique.

1 Like