How do I truncate tables properly?

Plan A: SET FOREIGN_KEY_CHECKS = 0; — Disable foreign key checking. TRUNCATE TABLE forums; TRUNCATE TABLE dates; TRUNCATE TABLE remarks; SET FOREIGN_KEY_CHECKS = 1; — Enable foreign key checking. Plan B: You should truncate child tables firstly, then parent tables. Disabling foreign key checks risks entering rows into your tables that don’t adhere to the … Read more

What exactly is the difference between a data mapper and a repository?

Suppose your application manages Person objects, with each instance having name, age and jobTitle properties. You would like to persist such objects, retrieve them from the persistence medium and maybe update (say, on their birthday, increment the age) or delete. These tasks are usually referred to as CRUD, from Create, Read, Update and Delete. It … Read more

What is the difference between the Data Mapper, Table Data Gateway (Gateway), Data Access Object (DAO) and Repository patterns?

Your example terms; DataMapper, DAO, DataTableGateway and Repository, all have a similar purpose (when I use one, I expect to get back a Customer object), but different intent/meaning and resulting implementation. A Repository “acts like a collection, except with more elaborate querying capability” [Evans, Domain Driven Design] and may be considered as an “objects in … Read more