Would like to link a record in my table to other records in the same table
Is there a straightforward way to create a link from one record in a table to several other records in the same table? Would appreociate some guidance or links to documents that describe this.
Thanks!
6 replies
-
Usually, you link records from one table to record(s) in another table. Is that what you want to do?
-
No, in this case I have one large table with names.
As an example, think of it as a table with 100's of people. Some of the people in the table are siblings. I want to be able to in a record indicate who the siblings are.
For example, when I open up Peter's record I want to be able to mark down that he is the brother to Paul and John, who also are part of the list of people in the table. Once I have marked it down in Peter's record, when I go to Paul's record I should see that he is brother to Peter and John, and when I go to John's record I should se that he is the brother to Peter and Paul.
-
It might be possible to do that with a single table, but would require some coding to do it. As long as the information you enter in Peter's record is unique enough to be able to filter out Paul's and John's records, you could copy the information to their records. Another possibility is a many-to-many relationship, but that would require 3 tables.
-
OK. Thanks.
I assume that going the path with three tables I would need to create a second table with only the names, and then a third table used to connect the name table with the main table to make the many to many relationship. If this is the approach the table with names would need to be in Sync with the main table, automatically adding names when new records were created in the main table, automatically deleting names when deleted from the main table. If this is the approach you are thinking of, how would you suggest keeping the main table, and the name table, in sync?
-
I am actually more comfortable and have more experience with coding. I haven't done much with many-to-many databases. I'll try to work something up when I can or someone else with more experience can jump in. Ninox also has the Webinars on Tuesdays.
-
I don't have a lot of time to work on this, but I did come up with something that works for a single table. You'll need to come up with something more unique than just a first name to filter the records though. I don't know what you know and don't know so I'm just throwing this out there.
Here's the code for the button...
var mySiblings := [""];
var sibCount := 0;
for rec in select People where Siblings != null do
mySiblings := split(rec.Siblings, ", ");
sibCount := count(mySiblings);
for i in range(0, sibCount) do
var person := (select People where Name = item(mySiblings, i));
person.(Siblings := rec.Name + for j in range(0, sibCount) do
if item(mySiblings, j) != item(mySiblings, i) then
", " + item(mySiblings, j)
end
end)
end
end
Feel free to ask questions and I'll answer when I can.
Content aside
- 4 yrs agoLast active
- 6Replies
- 1148Views