Debugging Delete

78 views
Skip to first unread message

Edward Chanter

unread,
Feb 19, 2021, 4:49:30 AM2/19/21
to cfwh...@googlegroups.com
Hey guys,

I've been having a really weird problem with deleteByKey(), it continually returns false even though the record is valid and the deletedat field is in place. I can create, read and update but I can't delete. This is a new install but the database is old. Is it possible if one or more tables don't have the correct date fields that this would cause a problem with the delete function?

My other question is, what's the best way to debug this? I looked through the wheels code and I know for sure that the "SELECT" part of the deleteByKey() function is working, it finds the correct record but can't seem to delete it. 

I have two other sites running Wheels and this didn't happen on either of them so I'm thinking that maybe it's something to do with the database.

If anyone has any ideas I'm all ears :-)

Happy Friday!

-= Ed

Edward Chanter

unread,
Feb 19, 2021, 9:41:49 AM2/19/21
to cfwh...@googlegroups.com
Further to this, I dumped out the SQL statement being generated:
image.png
There's nothing wrong with it that I can see. I'm using Andy B's logUserActions() plugin but it's not that because I tried it without the plugin as well. Create, Read and Update all work fine.

This makes no sense. Is it something in the database? I'm using SQL datetime as the field which has never caused a problem in the past. The only thing that's different with this site is that I have to manually set the name of the DSN because the name doesn't follow the wheels convention.


--

Edward Chanter

Technical Innovations Manager
Collaborative Connections Ltd.
www.cc.uk.com

Landline: 01273 327950
Mobile: 07866 365282
Skype: edward.chanter
LinkedIn: http://goo.gl/Vdxqh
Twitter: @edthetechie

Tom King

unread,
Feb 19, 2021, 9:49:45 AM2/19/21
to CFWheels
Do you get any further doing:

foo = model("foo").findOne(where="id = 1");
if(isObject(foo) && foo.delete()) {
// deleted
}

I find the findByKey methods..... inconsistent sometimes. 

Edward Chanter

unread,
Feb 19, 2021, 10:23:29 AM2/19/21
to cfwh...@googlegroups.com
Hi Tom,

Thanks for your reply, I just tried what you suggested but I got the same result. "Bonkers" is the only word I can think of. I've got two other wheels sites and have not seen this problem before on either of them. Same database (MS SQL Server), same basic structure, etc etc.
image.png

As a test I created a little custom model function to do the soft delete and that works perfectly.

If you have any more ideas then let me know, at least I can use a custom function if I need to and there aren't too many tables in this site to make that solution impractical.

If I ever find a solution myself I will update this thread.

-= Ed

--
You received this message because you are subscribed to the Google Groups "CFWheels" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfwheels+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cfwheels/c3551f8a-3f54-44d4-a0dc-923f02caf661n%40googlegroups.com.

Edward Chanter

unread,
Feb 22, 2021, 4:50:22 AM2/22/21
to cfwh...@googlegroups.com
Quick update to this thread, I noticed that the SQL database was set to a very old compatibility level (MS SQL 2008) so I created a new database and moved the relevant tables over. Delete works perfectly now.

I have no idea what aspect of the database config was the problem but the site was built at least 10 years ago.

Andrew Bellenie

unread,
Feb 22, 2021, 5:42:41 AM2/22/21
to ColdFusion on Wheels
Thanks for the update Edward.

I wonder if the old compatibility was causing issues with cfdbinfo, so wheels wasn't correctly identifying the column for soft-delete?

Edward Chanter

unread,
Feb 22, 2021, 6:10:01 AM2/22/21
to cfwh...@googlegroups.com
Hi Andy,

I don't think it was that because when I dumped out the SQL statement that wheels was creating both the deletedat and deletedby fields were correctly inserted.

The database in question was super-old and was originally created on a late 90s version of SQL Server which was then ported over to newer versions in successive upgrades without the website ever changing.

At least it's working now :-)

-= Ed

Reply all
Reply to author
Forward
0 new messages