Today's Smalltalk 4 You looks at deleting from a database using Glorp - or more properly, one of the things you need to do in order to have that work. If you want to see how to get Glorp set up on VA Smalltalk, go here. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:
You can also watch it on YouTube:
Today we'll look at how to delete data from a database using Glorp - or more properly, what you have to do in order to have that work. The code we are using is simple:
"deleting" myEmp := session readOneOf: Emp where: [:each | each firstName = 'Wilma2']. session delete: myEmp.
Executing that looks like it should work, but it does not. Why? Well, we need to go back to our descriptor, and how we defined the database mapping:
tableForEMP: aTable aTable createFieldNamed: 'first_name' type: (platform varChar: 50). aTable createFieldNamed: 'last_name' type: (platform varChar: 50).
We haven't defined a primary key. We can either define something simple (a one up number, perhaps), or tell Glorp to treat one of the columns as a primary key. Without that, Glorp can't locate the unique column that maps to the object. We'll do that in our next tutorial
Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.
[st4u164-iPhone.m4v ( Size: 2245832 )]