JForm/JTable and best practices for Data/database Normalization in Joomla 3.4+

250 views
Skip to first unread message

Walt Sorensen

unread,
Jun 30, 2015, 1:18:01 PM6/30/15
to joomla-de...@googlegroups.com
I'm curious what the community thinks best practices for Data/database Normalization in Joomla 3.4+ when using JForm/JTable?

Seems some people say you should override the save/load methods in your Model for using multiple tables to accomplish Data/database Normalization
Others imply that you should override the methods in your JTables
Still others suggest implementing data normalization by using custom form fields to extend JForm for data in other tables.
The Core CMS seems to use multiple controllers, models, tables, and views with a single view rendering all of these MTVC items together (at least I think that's what's going on in com_users)


Will all of those varying implementations, What are the best practices for Data/database Normalization for JForms with JTable interfaces in Joomla 3.4+ ?

Walt Sorensen

unread,
Jul 8, 2015, 12:22:50 PM7/8/15
to joomla-de...@googlegroups.com
Seems there is at least one more method for Data/database Normalization in Joomla 3.4+

Loading various plugins and using JEventDispatcher for event handling to deal with the additional tables through the plugins. (com_users appears to use this method in some model methods like getItems() )

Walt Sorensen

unread,
Jul 10, 2015, 3:49:10 PM7/10/15
to joomla-de...@googlegroups.com
Here is some additional information I have learned based on a number of Joomla programming books and other sources discussing Data/database normalization for PHP/MySQL (I'm a little surprised no one in the community has chimed in on this topic as normalization and relational databases seems fairly important to the design of applications).

Basic Normalization guidelines for Joomla
  • Data should be designed to a minimum Second Normal Form (2NF) i.e. No Repeating Rows
    • Meet 1NF requirements
      • No repeating columns
      • no cell contains more than one item (some judgment should be applied here)
      • separate table for each set of related attributes
        • give each table a primary key
    • 2NF stresses Eliminating Redundant Data
      • Create separate tables for sets of values that apply to multiple records.
      • every column must depend on the candidate (unique key) or primary key
      • Remove subsets of data that apply to multiple rows of a table and place them in separate tables.
        • Relate tables with a foreign key.
  • Each column in a table must have a unique name.
  • Each table must have a set of values that uniquely identify each row
  • Each table's row must be unique.

Johan Janssens

unread,
Jul 10, 2015, 7:58:30 PM7/10/15
to joomla-de...@googlegroups.com
Hi Walt,

The practices for 2NF are quite common among developers these days and accepted as default. 2NF was discussed widely a decade ago, today most developers know the basics and apply them.

About your questions, 2NF is about database schema design, it's not related to how and where you override/extend your code to implement your specific business logic. In an ideal world your database schema should be fully decoupled from the higher level implementation and objects. 

Hope that helps,

Johan

Walt Sorensen

unread,
Jul 11, 2015, 8:36:13 AM7/11/15
to joomla-de...@googlegroups.com
Thanks Johan,

I agree 2NF and data normalization is fairly common, it's not necessarily common with beginning and intermediate developers. I see a lot of questions outside this group on how to use two or more tables with JTable/JForm. Although the JDatabase tutorials in the JDocs covers connecting multiple tables for list queries, the JTable/JForm tutorials don't cover this at all. The developing an MVC component tutorial also doesn't really cover the topic of Normalized data/relational databases or provide any examples of that kind of use. 
  
I was mostly trying to open a discussion on the best practices for implementing the business logic for normalized data with JTable/JForm so we might have a discussion to work from for improving the joomla tutorials. 

Johan Janssens

unread,
Jul 11, 2015, 11:45:49 AM7/11/15
to joomla-de...@googlegroups.com
Hi Walt,

Never used the tutorials myself, with that said, improving documentation for beginning and intermediate developers is always a good thing.

Maybe you could start with defining a specific list of 3 questions/problems you would like the tutorials to cover, most happy to help you from there.

Johan

--
You received this message because you are subscribed to a topic in the Google Groups "Joomla! General Development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/joomla-dev-general/kHzuSDWw1Ng/unsubscribe.
To unsubscribe from this group and all its topics, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

Walt Sorensen

unread,
Jul 16, 2015, 9:08:54 AM7/16/15
to joomla-de...@googlegroups.com
Thanks Johan,

I think the three problems I would like the tutorials to cover at the moment are:

Extending JTable for a one-to-many and many-to-many results from foreign key relations

Using multiple JTable instances in a model (could be an extension of the Using_the_JTable_class tutorial )

Using multiple tables in the MVC (could be an extension of the Using_multiple_models_in_an_MVC_component tutorial but covering the J3.4 methods for each area MVC since they all have getInstance() or getModel() methods)

All the best,
~Walt

Johan Janssens

unread,
Jul 16, 2015, 5:07:34 PM7/16/15
to joomla-de...@googlegroups.com
Hi Walt, three prime choices, which one do you wanna tackle first ?

Johan

Walt Sorensen

unread,
Jul 16, 2015, 6:42:02 PM7/16/15
to joomla-de...@googlegroups.com
Hi Johan,

I think "Extending JTable for one-to-many and many-to-many results from foreign key relations" would be the best to tackle first.

All the best,
~Walt

Johan Janssens

unread,
Jul 16, 2015, 6:51:58 PM7/16/15
to joomla-de...@googlegroups.com
There you go, setup a Google Doc and start drafting I would say :)

--

Walt Sorensen

unread,
Dec 15, 2015, 1:03:18 PM12/15/15
to Joomla! General Development
I've been working on trying to discover enough information to be able to write up these topics. From my research it looks like JTable lacks any "getChildren" or "getChild" methods, Unfortunately creating such methods to enable the ability have 1:N, N:M is an ORM topic beyond my current skills. I think I'm more inclined to rebuild my project using FOF3 which does include such low level ORM functions or even to adopt JoOctrine to use Doctrine 2 ORM.
Reply all
Reply to author
Forward
0 new messages