0

Following my previous question here, is there a way to have the same behaviour as ON DELETE CASCADE (MySQL) with JayData?

If I delete a Test I would like all linked Chapters and Checks to be deleted. I tried this code:

myDB.onReady(function(){
    myDB.Tests.filter(function(test) { return test.Name == this.Name; }, {Name: myTest.Name}).forEach(function(test){
        console.log('Starting to remove '+test.Name);
        myDB.Tests.remove(test);
        myDB.saveChanges(function() {
            console.log(test.Name+' removed');
        });
    });
});

But it doesn't delete the children. Could it be linked with the declaration of Chapters and Checks in the context? JayData probably doesn't see them as children but as independent entities.

I've also seen somewhere that there is some configuration required to do cascading operations with SQLite. I guessed JayData would deal with that.

Community
  • 1
  • 1
Maxbester
  • 2,435
  • 7
  • 42
  • 70

1 Answers1

0

There is no such functionality in JayData. WebSQL/sqlite has this function built-in but indexedDb hasn't. We could implement it in indexedDb but nobody has asked for it. If you need it then please either add it to our backlog or create an issue on github.

Gabor Dolla
  • 2,680
  • 4
  • 14
  • 13
  • I am sorry, your answer is quite unclear. Does indexedDb have it or not (`indexedDb has this function built-in but indexedDb hasn't`)? Anyway, I made a request for this feature in your backlog. – Maxbester Mar 18 '13 at 12:10
  • sorry, fixed it, so websql/sqlite has this feature built-in, indexeddb hasn't, we try to have a common api, so for indexeddb we'd have to implement it ourself. Also sqlite has this feature since version X, so maybe we'd have to implement this for sqlite also for older phones... – Gabor Dolla Mar 18 '13 at 13:03
  • Ok and what is the syntax to delete cascade in websql/sqlite? Is it done automatically? I think I can wait for you to implement it for IndexedDb. For now, I will use websql since my application will be launched only in Chrome and Safari. – Maxbester Mar 19 '13 at 07:32
  • Sorry, maybe my answer was not clear enough again. It works in websql/sqlite if you use it natively but you can not use this functionality through JayData. If we create this functionality for indexeddb by implementing it in javascript then it will be available from JayData so that in websql we will use the native implementation and in indexeddb we use our own implementation but you as a developer will be presented with the same api. – Gabor Dolla Mar 19 '13 at 07:46
  • No your answer was clear this time. It is my fault I was half asleep! Thanks – Maxbester Mar 19 '13 at 09:13