Today's Smalltalk 4 Yougoes through deleting objects using Glorp - which requires us to specify a primary key in our table mapping. The initial setup used is described 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 - which means that we need to make a small modification to our #tableForEMP: method in class EmpSystem:
tableForEMP: aTable aTable createFieldNamed: 'first_name' type: (platform varChar: 50). (aTable createFieldNamed: 'last_name' type: (platform varChar: 50)) bePrimaryKey.
Note the small change - we've designated one column as the primary key. Ideally, that column would be more sensible than the one in this example, but the point is, you need to specify that. From here on out, Glorp will treat that column as the primary key, even if it's not specified that way in the database. Now we can actually do a deletion:
"deleting" myEmp := session readOneOf: Emp where: [:each | each firstName = 'Wilma3']. session delete: myEmp.
Executing that now works, and wraps the #delete: in a transaction for us. We can verify this by executing a query:
session readOneOf: Emp where: [:each | each firstName = 'Wilma3'].
And inspecting the results:
And that's about it for today.
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.
[st4u167-iPhone.m4v ( Size: 4667584 )]