Namekey to associate different data

  • Posts: 272
  • Thank you received: 3
  • Hikashop Business
13 years 11 months ago #4229

Hello,

we see that you are usually using namekeys to associated data from different tables together rather than auto-increment id field. Just out of interest what is the reasoning behind this? What are the pro and cons of doing so? It appears to make things slight more complicated, but the returned results are more human readable.

Yours curiously. James

Please Log in or Create an account to join the conversation.

  • Posts: 83007
  • Thank you received: 13398
  • MODERATOR
13 years 11 months ago #4230

Hi,

Namekeys are used when we need to insert default data across several tables.
For example, for the zones, the data is inserted in both zone and zone_link tables.
If we wanted to use zone ids in the zone_link table, after import the 5000 zones during the install, we would have to load all the zones ids to insert the correct links in the zone_link table. To do that we need to match one column value with the correpsonding id. If you suppose that two zones could have the same name or same code (that happens for some states actually), you need something else which is unique, thus the namekey field.
Also, that can be a savior in some extreme cases: suppose that you delete all your zones but that you already had orders with addresses. If we had used zone ids to dynamically link the country and the state from the zone table, the information will be completely lost. With namekeys, even if the name isn't "nice" it still contains the name of the zone.
Also, there is still a zone id which is auto incremented as it is still used in some cases.

Please Log in or Create an account to join the conversation.

  • Posts: 272
  • Thank you received: 3
  • Hikashop Business
13 years 11 months ago #4233

Thanks for the insight. I understand the logic. I will bear this in mind for future projects.

Please Log in or Create an account to join the conversation.

Time to create page: 0.061 seconds
Powered by Kunena Forum