Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Table and record ID as foreign keys when sharing a subform table with different main tables

Questions related to using nuBuilder Forte.
Post Reply
justme636
Posts: 21
Joined: Wed Dec 14, 2022 10:56 am
Has thanked: 6 times
Been thanked: 4 times

Table and record ID as foreign keys when sharing a subform table with different main tables

Unread post by justme636 »

Hello everyone,

I'm considering to use a subform table for two or more main tables and I wonder what is the best way (and if it is a good idea after all).

Let me explain my problem with a simple example: I have to tables 'customers' and 'products' and each needs a function for creating comments. This can be easily set up with two tables 'customers_comments' and 'products_comments', both again connected with the subform object to the records in their corresponding main tables. This principle sure works, but is redundant and becomes unintelligible with an increasing amount of additional main tables that need a "comment function" too.

So I thought about "sharing" a subform table with more than one main table. While creating records in a subform object of the main table is easy (corresponding table and foreign key is clear), the other way is difficult: When I create a new comment in my 'comments' table I cannot easily assign this back to a main table record, since I need not only the record ID as foreign key but also the table ID. For comments, the back link from subform table to main table is not that important, but I want to use this principle also for other purpose where I maybe also create/manage subform table objects and link them with a lookup object to a main table record afterwards.

First I tried to use two lookups object in the subform: The first to look up the table and the second should use the value as a hash cookie for the table/form where to look for the record. If that had work out, my problem would have been solved, but apparently the lookup object cannot handle hash cookies in their properties. Then I considered different ways to acomplish that, especially by setting hash cookies and/or some SQL browse with both information. Maybe even a third table to choose table IDs. My latest idea - roughly explained - was to set an hash cookie with the main table ID and insert it automatically in a new subform record and for the subform table - the other way - create a main table lookup (to get the main table ID) and use this table ID as a hash cookie for SQL browse of different table to pick one record from the previously chosen table.

I haven't tried this yet, but I wonder if there is an easier - and more native - solution for my problem. I would be happy if someone who solved an similiar problem would share the solution :)
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: Table and record ID as foreign keys when sharing a subform table with different main tables

Unread post by steven »

Hi justme636,

I would just add a comments field to both the customers and products tables.


Steven
A short post is a good post.
justme636
Posts: 21
Joined: Wed Dec 14, 2022 10:56 am
Has thanked: 6 times
Been thanked: 4 times

Re: Table and record ID as foreign keys when sharing a subform table with different main tables

Unread post by justme636 »

Hi Steven,

thank you for your quick reply! Your suggestion is a simple solution and probably the best option for some cases, e.g. here to save (one) comment for (one) record. But the comments are just one function that I used to explain my problem. For example, I also need subforms/-tables for files, images etc. where I do need not just one field or value, but several subrecords, since one main record can have more than one file, image...

Maybe I should have expressed my core question like this: Is it better to set up individual subtables/-forms for each main table/form (more redundancy, but less coding) or to use a shared subform/-table for different main forms/table (less redundancy, but a lot more additional coding). For the second option one main problem that sure is technically solvable is to set a second foreign key (the table ID). And if one would go with the second option: What would be the easiest way?

While I'm writing so much about my problem I more and more get the impression that it makes more sense to set up individual subforms/-tables. Although it is redundant to have multiple tables with the same columns and for the same purpose, it is easy to set up a new subform/-tables and the connection from one subform to one table is with subform and lookup objects natively supported by nubuilder.

What do you think, Steven? Are there any other ideas about this?
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: Table and record ID as foreign keys when sharing a subform table with different main tables

Unread post by steven »

Hello justme636,

Have you swallowed chatGPT?

Should we call a doctor?


Kind Regards

Steven
A short post is a good post.
justme636
Posts: 21
Joined: Wed Dec 14, 2022 10:56 am
Has thanked: 6 times
Been thanked: 4 times

Re: Table and record ID as foreign keys when sharing a subform table with different main tables

Unread post by justme636 »

Hi Steven,

I'm fine - thanks ;)
Sometimes describing precisely and weighting up different aspects helps me to find the right answer.
I'm sorry if I annoyed you with this.

I think I found a solution for me.

Thank you for your feedback.
Post Reply