Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » How To » many to many and field names
many to many and field names [message #521] Thu, 04 January 2007 11:10 Go to next message
interop is currently offline  interop
Messages: 45
Registered: October 2006
Member
The convention here is that all primary keys are named 'id' (1 pk per table) and all foreign keys are named <tablename>_id.

Unless I'm missing something this convention looks to create a lot of extra work for me. In particular in the list2 transactions.

e.g. if I have the following tables: group, group_employee,
and employee where group_employee is the link table between group and employee. when I want to do a list2 employees of a particular group I have to modify the where clause in the _cm_pre_getData function and change 'id' to 'group_id'. Then it doesn't look like I can display groups of a particular employee because how do I know to change 'id' to 'employee_id' or 'group_id'?

So, My question: Is this convention going to cause me too many problems or did I miss something?
p.s. Changing the convention is not a problem- so if you recommend that let me know.
thanks
Re: many to many and field names [message #522 is a reply to message #521] Thu, 04 January 2007 13:25 Go to previous message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
I avoid conventions like this because they cause more problems than they solve, just like the problem you have just encountered. See http://www.tonymarston.net/php-mysql/technicalkeys.html#wors e1 for a more detailed explanation of this problem.

Your problem is that the WHERE clause passed down from the parent form contains "id='something'" but the column name 'id' has to be translated into either 'employee_id' or 'group_id' depending on the parent form. It would be possible to obtain the name of the previous form using either the getPreviousScript() or getPreviousTask() functions, but I would strongly recommend dropping that convention and change the primary key for each table so that instead of 'id' you have '<tablename>_id' instead. This will cause fewer problems in the long run.


Previous Topic: displaying many to many relationships
Next Topic: List with pre-defined search active
Goto Forum:
  


Current Time: Thu Mar 28 17:36:26 EDT 2024

Total time taken to generate the page: 0.01000 seconds