Sometimes it's OK to break the rules.

Website content in Dialogs is defined by information structures we call “Lists”. Each List corresponds to a MySQL table within the Dialogs database. Dialogs presents a simple interface to the developer for List creation and maintenance so developers don’t have to directly interface with MySQL unless they want to. For those more technical developers wanting to understand how to optimize content maintenance and website performance, some basic SQL skills and some insight into how Dialogs List Templates are used to map database fields into rendered pages goes a long way.

It is quite common for data in one Dialogs List to be related to another. Imagine a List of Artists and a companion List of the art they’ve created. Relational database theory defines a certain way to manage that interrelation according to something called third-normal-form (3NF). Among other things, 3NF states that no information should be duplicated in both tables. Is that really a rule that shouldn't be broken? In the days of expensive storage and crude data handling tools, it sure made sense. Adhering to 3NF, however, makes for unnecessarily complex SQL within Dialogs List Templates, something that for efficient development and ongoing maintenance we'd like to avoid. Here's an example to illustrate the problem. Lets say you have these two tables:

Artist
item_iditem_name
1Vermeer
2Rubens
3Michelangelo
Art
item_iditem_nameartist_item_id
1The Milkmaid1
2Hippopotamus Hunt2
3David3
4Sistine Chapel ceiling3
5Pieta3

The relationship between the tables is obvious. The 'artist_item_id' field 'links' to the item_id of the 'artist' table.

If you want to display the art that's easy:

SELECT * FROM art
... but if you want to include the name of the artist it's this mess:
SELECT art.*,artist.item_name AS artist_item_name 
FROM art LEFT JOIN artist ON art.artist_item_id=artist.item_id 
WHERE artist.item_id IS NOT NULL
Yuck!! And it's worse than that. If you want to specify a sort you can't just say
ORDER BY item_name
you have to remember to prefix the table name and the same goes for anything in the 'WHERE' clause as well.

It's time to go off the reservation. If we break from the 3NF rules and add the artist's name to the art table we would get this:

Art
item_iditem_nameartist_item_idartist_item_name
1The Milkmaid1Vermeer
2Hippopotamus Hunt2Rubens
3David3Michelangelo
4Sistine Chapel ceiling3Michelangelo
5Pieta3Michelangelo
Super! Now we're back to
SELECT * FROM art
... and we have the artist's name! The only problem is, if Michelangelo's name is misspelled, and someone changes it in the 'artist' table, it will still be wrong in the 'art' table. This is where Dialogs shines. All we have to do is add one line to the list automation script which gets run for every edit to a list item. This one line will update the art table and keep the artist's names in sync with the 'artist' table:
$this->query("UPDATE art LEFT JOIN artist ON art.artist_item_id=artist.item_id
  SET art.artist_item_name=artist.item_name");
Cons:
  1. Causes baldness in database purists.
  2. Wastes hard drive space.
Pros:
  1. Easy to implement: add one more field to the list, add one line to the automation script.
  2. Dead simple list templates because all the fields you need are there.
  3. CSV and XML exports have all the fields you need too.
  4. Hard drive space is beyond cheap.

Dialogs is a real-world development tool for the professional web developer. We developed Dialogs with the belief that successful deployments either follow best-practices or define them. So go ahead, break the rules. We won't tell your database theory professor. For more detailed description of how to do this in Dialogs see the Knowledge Base Article.

Recent Articles

Look for Opportunities to Change
How you do business may no longer be competitive.

Q&A About Responsive Design
A well thought out discussion with one of our amazing clients.

Ashley Madison Hack: Lessons for Any Business
Security isn't an expense, it's an investment.

SSL is Dead. Long Live TLS.
Dialogs is no longer running SSL for web hosting. Learn how that may affect your company.

Happy 20th Anniversary!
A lot has happened on the internet in 20 years. We have seen it all.

It’s Time to Sell The Studebaker
Over time, many products don’t just change, they get better.

The Couch is Your Enemy: 5 Work-At-Home Pitfalls
Don't let kitten pics and comfortable furniture ruin your productivity.

What You Know Has Real Value.
Is your expertise marketable? Leverage it!

Stay Fit at Your Desk Job: Stand and Walk!
Working a computer job doesn't have to mean living a lethargic life.

Why Javascript?
Keeping up with current technology is not such a bad thing.

Our customers say it best

The Dialogs Team helped come up with a solution that tackled our highly technical, data-intensive challenges and provided a user-friendly interface on the backend to manage our data.

Ryan M.