breeze - delete entities from junction table in many to many relationship -
i have many many relationship junction table.
public class contact { public int id { get; set; } public string name { get; set; } public virtual icollection<contactcontactgroup> contactcontactgroups { get; set; } } public class contactcontactgroup { public int id { get; set; } public int contactid { get; set; } public int contactgroupid { get; set; } public virtual contact contact { get; set; } public virtual contactgroup contactgroup { get; set; } } public class contactgroup { public int id { get; set; } public string name { get; set; } public virtual icollection<contactcontactgroup> contactcontactgroups { get; set; } }
if delete relation following exception:
uncaught typeerror: unable parse bindings. bindings value: text: contact().name message: cannot read property 'name' of null
this delete function:
that.deleteme = function (contactcontactgroup) { // doesn't work also, duplicates entries after second deletion //contactgroup.contactcontactgroups.remove(contactcontactgroup); contactcontactgroup.entityaspect.setdeleted(); };
here view:
<div data-bind="foreach: contactcontactgroups"> <div data-bind="text: contact().name"></div> <button data-bind="click: deleteme">delete</button> </div>
i've found workaround 'with' binding knockoutjs:
that.deleteme = function (contactcontactgroup) { contactgroup.contactcontactgroups.remove(contactcontactgroup); contactcontactgroup.entityaspect.setdeleted(); }; <div data-bind="foreach: contactcontactgroups"> <div data-bind="with: contact"> <div data-bind="text: name"></div> </div> <button data-bind="click: deleteme">delete</button> </div>
but seems little odd me. breezejs bug or did miss something?
what bug be? knockout requires object bind , when delete property of object break binding.
if using junction table 'removing' 1 side of before custom save, sounds you've found problem in logic. instead of removing contactcontactgroup contactgroup, why don't set both sides of binding null before delete view (probably) doesn't have reason bound it?
that.deleteme = function (contactcontactgroup) { contactcontactgroup.contact(null); contactcontactgroup.contactgroup(null); contactcontactgroup.entityaspect.setdeleted(); entitymanager.savechanges(); };
edit
looks problem because of method binding, showing junction table in view instead of showing relationship between 2 properties. problem in knockout still, , it's inability display binding have removed. more shorthand version of trying fix issue encountering...
<div data-bind="foreach: contactcontactgroups"> <div data-bind="text: $data.contact().name"></div> <button data-bind="click: deleteme">delete</button> </div>
Comments
Post a Comment