How to create a 1:M display?
In the display above, I've attempted to show the tasks for each employee (M:1). Although the tasks for this employee shown at the bottom are correct, the possibly many tasks display isn't a "grid" (vertical display with one record per row) as wanted. I've struggled with this for several hours and am wondering what the trick is to reformat the Tasks for Employees so there is just one row per task (like a grid).
If I try to add a view as a field and reference the Tasks table, it says that no data is returned. Nothing is displayed in this case.
Very frustrating product with little if any useful documentation I've found.
Thanks,
8 replies
-
The "intermediate example" is not really very relational. There is no foreign key that I saw linking Events to Company. Thus, you type a pop-up to see the company form a list? Also, I could, as noted above, not find any example of showing a list of matching children for a given parent.
Thanks.
-
In Ninox there is no "foreign key" that used to link tables. Meaning there is no specific field that you select to link records. Ninox does that for you.
What you do is create on the table that is the "many", for you it would be tasks, you create a reference field to the 1, or employees. After you create the field the field header should read:
Reference from Tasks to Employee (N:1)
From the looks of your picture you have done it the other way around.
When done correctly Ninox will automagically create a table in Employee showing all task records related to the employee record. From the looks of your picture you have created the reference field in Employee to tasks.
-
I want to display all the tasks for each employee. The multiple tasks do show up, but not in a list.
An employee can have zero, one, or many tasks. I want to show the tasks for each employee on the employee form in a grid display.
I add the constraint employee.emp_pk = tasks.emp_fk since in the 1:M form, I only want to see the related tasks.
-
"Trust the force, Luke"
Let Ninox handle the relationship for you. You don't need to set any constraints or do any extra work.
Did you try creating the reference field in Tasks not in Employees?
-
Yes, but it does not work.
If I have 10 tasks and 20 employees, how can Ninox "know" which tasks go with which employees and display them without a foreign key mapping them (or without an explicit assignment step by the user -- who may not be the one who knows anything about tasks for users).
Task
Clean BasementWash Car
-----------------
Employee
AlanRobert
From this list, with no foreign key mapping, can you tell me who does which tasks? Right now, I don't know either so how could Ninox possibly know?I don't think the force is going to know, either...
-
I thought you would be creating the links. You have to create the link manually at sometime.
I guess I should have realized you already have employee data in your task table. Since you have a constraint set.
Are you trying to transition to a relational link between the two tables that you didn't have before?
If you don't want to create the relationship and just use the data that is in Tasks you can create a view element in Employee that has the following in the formula:
let t := this; (select Tasks)[emp_fk = t.emp_pk]
the field oldEmployee is a simple text field that I use to match the Name field in Employee.
If you want to create relationships then you can put this in a button in Tasks to test out the code:
let t := this; let xEM := first((select Employee)[emp_pd = t.emp_fk]); Employee := xEM
In line 2 we have to use the first command cause Ninox always returns an array even for 1 record so we have to tell Ninox that we only want the first record since we know we will only find 1.
If that works then if this is a one time action, you can select Update Multiple Records.. then next to the reference field to Employee select Assign Calculated Value and put this in:
let t := this; first((select Employee)[emp_pd = t.emp_fk]);
If you want a button that you can use repeatedly we would have to create a loop, so let me know if you want to go that route.
Content aside
- 2 yrs agoLast active
- 8Replies
- 81Views
-
2
Following