Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breeze.js: error when assigning compound foreign key with GUID and integer values

I'm encountering an error with Breeze.js version 1.4.12. I have an entity, OrderLine, that has a compound primary key consisting of one GUID field (OrderId) and one integer field (LineNumber). This entity has a self-referencing foreign key, consisting of two fields: DependsOnOrderId and DependsOnLineNumber.

When creating a new instance of the OrderLine entity, and passing an object of initial values, I can assign values to the foreign key fields and everything works as expected. However, my issues lies when trying to assign values after entity creation. Assigning a value to the DependsOnOrderId property works correctly. When I assign a value to the DependsOnLineNumber property, I receive an error message: Type Error: undefined is not a function. This error occurs at line breeze.debug.js:4275 and a debugging session shows that it is trying to run a toLowerCase() method on the integer field value of the compound key.

The two lines that appear to be causing the issue are referenced below:

if (kp.dataType === DataType.Guid) {
    keyValues[i] && keyValues[i].toLowerCase();

I was able to resolve this issue satisfactorily by adjusting the lines to read:

if (kp.dataType === DataType.Guid) {
    keyValues[i] = keyValues[i] && ( ( keyValues[i].toLowerCase && keyValues[i].toLowerCase() ) || keyValues[i] );

This was only put together as a proof of concept to resolve the issue and has not been tested in all cases, but it ensures that when comparing a non-GUID value that is part of a GUID/non-GUID composite key, a toLowerCase() call is not attempted against a value that does not have that method.

Has anyone else encountered this error or have suggestions for fixing? I was thinking of putting together a pull request on GitHub, but wanted to check to see if there were other instances of this issue, or possible side effects with my suggested fix.

Thanks!

like image 658
aifdsc Avatar asked Jan 24 '26 17:01

aifdsc


1 Answers

Your fix looks good, and I've added it to [email protected]

Thanks for your help on this. And sorry it took so long.

like image 151
Steve Schmitt Avatar answered Jan 27 '26 19:01

Steve Schmitt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!