Note that there are some explanatory texts on larger screens.

plurals
  1. POBreeze.js: adding an element to a navigation property collection without inverse rel raises an exception [Unable to get value of the property 'name']
    text
    copied!<p>I have two entities in my EDM, <code>Application</code> and <code>Address</code> pretty much like the following:</p> <pre><code>class Application { ICollection&lt;Address&gt; Addresses { get; set; } } class Address { } </code></pre> <p>On the client, I create an instance of each and try to add the <code>address</code> instance to the <code>Application.addresses</code> collection:</p> <pre><code>var address = addressType.createEntity(...); var application = applicationType.createEntity(...); application.addresses.push(address); </code></pre> <p>Unfortunately, I get a runtime exception saying: "<code>Unable to get value of the property 'name': object is null or undefined</code>".</p> <p>I tracked the exception back to the <code>checkForDups</code> function in <code>breeze.debug.js@9393-9404</code> (v1.2.8):</p> <pre><code>function checkForDups(relationArray, adds) { // don't allow dups in this array. - also prevents recursion var inverseProp = relationArray.navigationProperty.inverse; var goodAdds = adds.filter(function(a) { if (relationArray._addsInProcess.indexOf(a) &gt;= 0) { return false; } var inverseValue = a.getProperty(inverseProp.name); return inverseValue != relationArray.parentEntity; }); return goodAdds; } </code></pre> <p>As it happens, my entities are in a one-to-many unidirectional relationship (without an inverse navigation property); as a result at runtime <code>relationArray.navigationProperty.inverse</code> is <code>undefined</code> and so the error when trying to access the <code>name</code> property.</p> <p>Adding a simple check fixes the problem, and allows adding to the collection:</p> <pre><code>if (!inverseProp) { return true; } </code></pre> <p>So after all this the question is: is this a bug or is it simply that Breeze does not support one-to-many unidirectional?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload