0
votes

by working with jaydata i am adding entities to a tree structure with deep nesting of entity-objects.

I attach the upper entity to the context and edit/add/remove related child entities. At the end i use saveChanges() with a promise.

The count-value passed to the promise tells that all changed entities have been counted correctly but saveChanges() didn't execute a batch request, persisting these entities.

So it feels like nothing else happens, but counting entities.

I post a small code example. I am quite sure, that the references of the entites are set correctly. (Working with jaydata, odata v4, web api and angularjs)

Is someone else having this problem with jaydata and found the reason?

Thanks for your help. =)

Greetings Paul

// Attach upper entity
DataService.jaydata.attach(viewModel.currentSkillTree.entity);

// Generating new entities
var newSkill = new DataService.jaydata.Skills.elementType({
    Id: undefined,
    Name: 'New skill',
    Levels: [],
    IconId: 47,
    SkillTreeUsage: []
});

var newSkillLevel = new DataService.jaydata.SkillLevels.elementType({
    Id: undefined,
    ShortTitle: 'New level',
    Skill: newSkill,
    SkillId: undefined,
    Level: 1,
    RequirementSets: []
});

var newRequirementSet = new DataService.jaydata.RequirementSets.elementType({
    Id: undefined,
    SkillLevel: newSkillLevel,
    SkillLevelId: undefined,
    SkillTree: undefined,
    SkillTreeId: viewModel.currentSkillTree.entity.Id,
});

var newSkillTreeElement = new DataService.jaydata.SkillTreeElements.elementType({
    Id: undefined,
    SkillTree: undefined,
    SkillTreeId: viewModel.currentSkillTree.entity.Id,
    Skill: newSkill,
    SkillId: undefined,
    Position: { X: x, Y: y }
});

// Completing object-references

viewModel.currentSkillTree.entity.Elements.push(newSkillTreeElement);

newSkill.Levels.push(newSkillLevel);

newSkill.SkillTreeUsage.push(newSkillTreeElement)

newSkillLevel.RequirementSets.push(newRequirementSet);

// Saving
DataService.jaydata.saveChanges()
.then(function (cnt) {

    console.log('Saved entities:', cnt);

    // The cnt-result in console is 4 
    // But no request was executed, nothing was saved 

}, function (exception) {
    console.log(exception); // Also no exception was thrown
});
1
Is there somebody or is jaydata at the end of its livecycle? For everybody experimenting with jaydata: I cannot recommend using it. The documentation sucks, is too small, is incomplete and the higher the version of jaydata gets the more outdated the documentation becomes. I'm not lying, i say it as it is. And nobody is there that feels responsible for that, also known bugs stay opened and don't get fixed over years.Paul Holland
Thumbs down, totally. Don't use jaydata! Better be warned and beware your good karma. Using jaydata will destroy it. (For weeks and months lost in outdated posts and script snippeds and still not finding solutions when it gets complex and tricky) And to developers of jaydata: Stop the developement. Wake up and take it from the net. You just keep wasting peoples time. You can't handle, you can't afford what it takes to serve a well done open source library anymore. Nobody should step into your quick and dirty trap. angryPaul Holland

1 Answers

0
votes

So to not be that unkind.

The solution to solve the problem above to me, since i tried nearly every combination with entities (adding, attaching, .save(), .saveChanges(), object-references etc, figuring out it doesn't make sense anyway, it just acted the same way and seems to be so buggy), ended up within a workaround acting with classic nested async calls.

The solution was to save entities seperately within nested promises and to turn off the batch behavior of jaydata, to avoid double requests.

You can find the option within $data.defaults

$data.defaults.OData.disableBatch = true;

As result i am dealing now with good old nasty pyramids of doom, which at least gave the possibility back to save entities in the right order, with full control, the way the api needs it.

      // Saving new SkillLevelRequirement connection
      if (isConnectionGiven === false) {

        // The first level of source skill where the target-skill-requirement will be added
        var sourceSkillLevel = Enumerable
          .From(sourceSkill.Levels)
          .FirstOrDefault(null, function (x) {
            return x.Level === 1;
          });

        // The last level of the target-skill to solve
        var targetSkillLevel = Enumerable
          .From(targetSkill.Levels)
          .FirstOrDefault(null, function (x) {
            return x.Level === targetSkill.Levels.length;
          });

        // First set of first level from source skill (will be used to add skilllevel-requirement)
        var firstRequirementSet = sourceSkillLevel.RequirementSets[0];

        // New RequirementAsignment
        var newRequirementAssignment = new DataService.jaydata.RequirementAssignments.elementType({
          RequirementSetId: firstRequirementSet.Id,
          Order: 1
        });

        // New Requirement
        var newRequirement = new DataService.jaydata.Requirements.elementType({
          Title: requirementTypes.SKILL_CONNECTION,
          RequirementOfIntId: undefined,
          RequirementOfBoolId: undefined,
          RequirementOfSkillLevelId: 0
        });

        // New RequirementOfSkillLevel
        var newRequirementOfSkillLevel = new DataService.jaydata.RequirementsOfSkillLevel.elementType({
          SkillLevelId: targetSkillLevel.Id,
        });

        // Loading symbol
        showBusyIndicator();

        newRequirementOfSkillLevel.save()
        .then(function () {
          newRequirement.RequirementOfSkillLevelId = newRequirementOfSkillLevel.Id;
          newRequirement.save()
          .then(function () {
            newRequirementAssignment.RequirementId = newRequirement.Id;
            newRequirementAssignment.save()
            .then(function () {

              // Loading symbol will be closed after tree reloaded
              reloadCurrentTree();

            }, function (exception) {
              showJayDataExceptionModal(exception);
            });
          }, function (exception) {
            showJayDataExceptionModal(exception);
          });
        }, function (exception) {
          showJayDataExceptionModal(exception);
        });

      }
    }

@jaydata developers: Thanks for 42 new grey hairs. I'm still at the point where i think i am using your tool wrong and jaydata could do so much better. Better up your documentation, sieriously. No desserts for you today.