Note that there are some explanatory texts on larger screens.

plurals
  1. POBreeze Setting Multiple Foreign Keys On The Client-side
    primarykey
    data
    text
    <p>I have three breeze entities, my application is a long form that adds records to all three tables at once before going to the server for a save. Two of the tables Drivers &amp; Vehicles have a relationship to AutoLead and need the AutoLeadId from the AutoLead table that is being entered all at once on the client side.</p> <p>So I have a form, the user entered information into AutoLead, then adds records into the Drivers and Vehicles tables in one seamless form. How do I get the Id to assign to Drivers and Vehicles without first separating the saves out, and saving the AutoLead first, returning the new Id and then assigning it to Drivers and Vehicles before saving them again. I want to avoid multiple trips to the server just to generate the Id's for the navigation properties on Vehicles and Drivers.</p> <p>From what i understood, breeze was supposed to be able to fixup these ID's using the temporary ID's from the client side it creates. But when i go to do a save it isnt changing these ID's. According to: <a href="http://www.breezejs.com/documentation/navigation-properties" rel="nofollow">http://www.breezejs.com/documentation/navigation-properties</a></p> <p>If i try to set the navigation property directly with objects, I get an undefined error for the navigation property (See code below). Using another approach, If I try to set the foreign key directly on their Id's I get a foreign key error from SQL because its trying to push -1 to the server (the temporary ID's). I know I must be doing something wrong. Here is some of my code:</p> <p><strong>Create new client side entities:</strong></p> <pre><code> // New entity creation functions var createAutoLead = function() { return manager.createEntity('AutoLead'); }; var createAutoLeadDriver = function () { return manager.createEntity('AutoLeadDriver'); }; var createAutoLeadVehicle = function () { return manager.createEntity('AutoLeadVehicle'); }; // Save Function Loop through all drivers and vehicles and set their autoLeadId's before saving var saveAutoLead = function (newAutoLead, autoLeadDrivers, autoLeadVehicles) { // Loop through drivers and set the foreign keys for (var i = 0; i &lt; autoLeadDrivers().length; i++) { autoLeadDrivers()[i].autoLead(newAutoLead); } // Loop through drivers and set the foreign keys for (var i2 = 0; i2 &lt; autoLeadVehicles().length; i2++) { autoLeadVehicles()[i2].autoLead(newAutoLead); } manager.saveChanges() .then(saveSucceeded) .fail(saveFailed); function saveSucceeded() { return logger.log('Debug Message', 'Quote saved successfully', null, system.getModuleId(datacontext), true, config.growlTypes.success); } return logger.log('Debug Message', 'Quote saved successfully', null, system.getModuleId(datacontext),true, config.growlTypes.success); }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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