jayman
Posts: 3
Joined: Wed Sep 16, 2020 10:17 pm

Can't get Update and Delete to work with MySQL Backend

Hi all,

I have taken the tutorial at https://docs.appery.io/docs/ionic-4-todo-list-tutorial and have gotten it to work with the Appery.io database; but longer term I want to write an app that can CRUD (Create, Read, Update, Delete) entries with my existing database.

I was able to expose my database (MySQL running on AWS) via the API Express and I then modified the above tutorial to use this datasource for my app. I am able to view a list of items in my own database and I can add new items. However, I cannot delete or update items in my database.

When I try to delete an item nothing happens, but if I view my console in Chrome I see an error of "Can't perform 'delete' on todoDB_task_, object ID is empty". I suspect that the ID of the task is not being passed to the code to delete it. When I look at the related code I do see this error of "Cannot Find Name 'taskId'".

Any ideas? I also cannot edit entries, but it seems to me that create and list don't need to taskId passed, but Update and Delete do???

Help! Thanks in advance

Jay

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Re: Can't get Update and Delete to work with MySQL Backend

Hello Jay,

This tutorial uses Appery.io database, so some issues might happen if you use your own - it is not a problem, we will help you to solve it.

Of course you should pass the id to the delete service to make the database know the id to delete.

The question is: does your database table have the id column?

How do you pass the selected item id there? The same as it is shown here? https://docs.appery.io/docs/ionic-4-tod ... ting-tasks

jayman
Posts: 3
Joined: Wed Sep 16, 2020 10:17 pm

Re: Can't get Update and Delete to work with MySQL Backend

Apologies - I only saw your kind response now... to answer your questions (both using references to "https://docs.appery.io/docs/ionic-4-tod ... ting-tasks"):

  1. Does your database table have the id column?

At the Database step "New taskName column appears in the table"... I see that the Appery Database adds a column with the name "_id"... I did the same in MySQL
CREATE TABLE tasks (
_id int(11) NOT NULL AUTO_INCREMENT,
taskName varchar(100) DEFAULT NULL,
_createdAt datetime DEFAULT NULL,
_UpdatedAt datetime DEFAULT NULL,
PRIMARY KEY (_id)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;

  1. How do you pass the selected item id there?

Similar to the Appery.io example, I add it to the edit button:
i = editTask(task.id, task.taskName):[/i]
or I add it to the delete button:
i = deleteTask(task.id):[/i]
The related code for deleteTask then includes that I add "_id": taskId to the params block etc.

Thank you in advance!
Jay

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Re: Can't get Update and Delete to work with MySQL Backend

Could you just test it with the static ID value? Once it is working fine we will move on to pass the correct it there.

But it seems you just need to pass the id parameter there, not id, so your code should be:

Code: Select all

deleteTask(task._id)

Please check the database response with the correct object structure to be sure you do it right

jayman
Posts: 3
Joined: Wed Sep 16, 2020 10:17 pm

Re: Can't get Update and Delete to work with MySQL Backend

Hi,

Thanks for your ongoing help.

Firstly on the code - I set the button to have deleteTask(task._id) as the action when I click, but it still does not work.

Next, I then went into the service "todoDB_task_delete" and added the ID of an existing MySQL DB entry as the Value in the Request tab.
When I tested the app, clicking the button deleted the DB entry with that number as the _id... so I know the code works when it gets the right data passed to it.

I then went into the code for deleteTask - just to confirm it has taskId as an argument

Error.jpg
Error.jpg (159.6 KiB) Viewed 6264 times

- changing this to id doesn't seem to help.
I do notice that if I am using the Appery.io database or my own database, I see an error for where I have added "id": taskId to the params block.
There is a red box and the error is Cannot find name "taskId".

Any other ideas?
Thank you

JMC

Return to “Issues”