node.js - sequelize CreateAssociation return parent instance instead of child created instance -
i have issue createassociation method.
here's code :
user create curves
//user create curves function savecurves(user, functions){ var curves = json.parse(functions); (var = 0; < curves.length; i++) { (function(i,user,curves){ user.createcurve({ i_min: curves[i].i_min, i_max: curves[i].i_max, }).then(function(curve){ savefunction(curve,curves[i].fn,curves[i].variables); }); })(i,user,curves); } } //save function after creating curves depends on function savefunction(curve,fct,variables){ return curve.createfunction({ fn: fct }).then(function(math_function){ savevariables(math_function,variables); return; }) } //save variables associated function function savevariables(fn, variables){ for(var j= 0; j < variables.length; j++){ (function(j,fn,variables){ fn.createvariable({ name: variables[j].name, function_id: fn.id }) .then(function(row_variable){ console.log(row_variable.tojson()) return row_variable.createfunction({ fn: variables[j].fn }) })(j,fn,variables); }
i have issue when i'm calling "fn.createvariable" method. don't understand why promise in .then after give me fn instance instead of variable instance.
and have error : unhandled rejection typeerror: row_variable.createfunction not function
when i'm looked database, saw instance has been correctly inserted row_variable in console.log give me fn , not inserted row.
so cannot understand have return. did above, why doesn't work here ?
(not relation definition issue because row exist in database)
any idea please ?
Comments
Post a Comment