Home » RADICORE » How To » LIST3 linked from LIST1 (LIST3: As I scroll through the parents, or children, the grandchild does not change)
|
|
Re: LIST3 linked from LIST1 [message #4818 is a reply to message #4816] |
Thu, 09 July 2015 16:17   |
rafs
Messages: 69 Registered: May 2015
|
Member |
|
|
AJM wrote on Thu, 09 July 2015 05:44If the are any differences between the name of the primary key in the parent table and the name of the corresponding foreign key inb the child table, then you must convert the field name manually in your code as the framework cannot do this automatically.
I am following the convention that every table's primary key is called 'id', and every table's foreign key is called <referenced-table>_id. This is the convention that I picked up from CakePHP, and probably RoR. This convention was a requirement for the project. So, for example, packages has many files (WHERE packages.id = files.package_id), and files have many lines (WHERE files.id = lines.file_id).
The parent to child part works when using this convention, but that the child to grandchild linking does not.
[Updated on: Thu, 09 July 2015 16:50] Report message to a moderator
|
|
|
Re: LIST3 linked from LIST1 [message #4819 is a reply to message #4816] |
Thu, 09 July 2015 16:55   |
rafs
Messages: 69 Registered: May 2015
|
Member |
|
|
AJM wrote on Thu, 09 July 2015 05:44If the are any differences between the name of the primary key in the parent table and the name of the corresponding foreign key inb the child table, then you must convert the field name manually in your code as the framework cannot do this automatically.
I thought that the point of defining the relationships in the data dictionary was to handle these linking fields for me? When I defined the child relationships for the parent tables, it explicitly asks me to specify which field in the junior table is the foreign key to the primary key of the senior table, so this mapping should be handled automatically by the framework, no?
For example, Figure 13 in the first tutorial. Your xample db x_option table is linked tho x_pers_opt_xref WHERE "x_option.option_id = x_pers_opt_xref.option_id". I assumed that the fields need not have the same name.
[Updated on: Thu, 09 July 2015 17:00] Report message to a moderator
|
|
|
|
|
Re: LIST3 linked from LIST1 [message #4822 is a reply to message #4818] |
Fri, 10 July 2015 04:43   |
AJM
Messages: 2382 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
rafs wrote on Thu, 09 July 2015 21:17
I am following the convention that every table's primary key is called 'id', and every table's foreign key is called <referenced-table>_id. This is the convention that I picked up from CakePHP, and probably RoR. This convention was a requirement for the project. So, for example, packages has many files (WHERE packages.id = files.package_id), and files have many lines (WHERE files.id = lines.file_id).
That may be a convention that some newbies with lesser experience follow, but the convention that I and my fellow developers have been following since the 1970s is that wherever possible the same column should have the same name regardless of which table it's on. All the SQL samples you see on any vendor's website still follow this convention, which is why you see "customer.customer_id" and not "customer.id". Note also the use of snake_case and not CamelCaps.
|
|
|
|
|
|
Re: LIST3 linked from LIST1 [message #4835 is a reply to message #4813] |
Sat, 11 July 2015 18:19   |
rafs
Messages: 69 Registered: May 2015
|
Member |
|
|
I originally skipped over your articles on database stuff. I have read them now. I guess I am rated as a novice with borderline nincompoop tendencies.
Anyways, I didn't see anything explicitly about the following (hypothetical) situation. A parent has many children, but always has a favorite (favourite) child. Are there any special considerations to be aware of? I would assume that I can just define each of these FK relationship in the data dictionaries, but I wonder if I will have to add some code since parent.child_id_favorite and child.child_id have different names.
parent
------
parent_id int primary key,
parent_name char(10),
child_id_favorite int,
FOREIGN KEY (child_id_favorite) REFERENCES child(child_id)
child
-----
child_id int primary key,
parent_id int,
child_name char(10),
FOREIGN KEY (parent_id) REFERENCES parent(parent_id)
Thanks.
[Updated on: Sat, 11 July 2015 18:22] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Wed Jun 18 15:13:36 EDT 2025
Total time taken to generate the page: 0.02059 seconds
|