0:1 relationship

mariluzrm

Member
Hello.

I would like to know how I can render the attached model in Fabrik. In "TOOL" table I have field1, field2, ... tool_type (values: saw / hammer / wrench / screwdriver).

01 relationship.png

When adding a new row the tool_type field should be shown and when the user fills in the value (e.g. hammer) only the hammer fields should be shown (or the fields of another type of tool if the user selects another type).

Thanks!!!
 
So you want the user be able to add new tool-types?
Dbjoin element and dropdown element have "Add option in frontend" resp "Frontend additions" possibilities.
 
So you want the user be able to add new tool-types?

No. It is to have an inventory of tools. User will add tools (many of each type):

saw1, saw2, ..., sawN, hammer1, ... hammerM, wrench1, ......

User will add tools (of one of those types). A tool can be a saw, a hammer, a wrench or a screwdriver. A tool is just one of those types. (0:1 relationship)

The tools in a simple example so that it is well understood. Actually the database is of damage to bridges: breaks, cracks, dampness...
 
Last edited:
Then why not simply make them radios (for single choice) or checkboxes (for multiple choice):
Element "saw": options saw1, saw2, saw3 ...
Element "hammer": options hammer1, hammer2, hammer3 ...
...

Or maybe I (still) don't get it... :confused:
 
No, is not that.
Imagine a workshop with many tools of these types, you have to enter them in the databases. There are 5 tables, one is the main table (TOOL). When registering a tool, the tools table will always have a record and the other 4 tables, only one of the four will have a record, depending on the type.

It would be similar to the PERSON, TEACHER, AND STUDENT tables. When registering a STUDENT record, it will have a row in the PERSON table and in the STUDENT table. And when registering a teacher record, it will have a row in the PERSON table and in the TEACHER table
 
If I understand this correct, you could have a separate table with tool types where you have saw, hammer, wrench etc.

And in the main table, where the user enters the tool e.g. hammer1, he/she selects the tool type from the databasejoin element which refers to "tool types" table.

And if you want to have separate views for e.g. only hammers or wrenches, you can have separate menu items with different pre-filters. So no need to have 4 different tables.
 
If I understand this correct, you could have a separate table with tool types where you have saw, hammer, wrench etc.
Correct


And in the main table, where the user enters the tool e.g. hammer1, he/she selects the tool type from the databasejoin element which refers to "tool types" table.
Ok


And if you want to have separate views for e.g. only hammers or wrenches, you can have separate menu items with different pre-filters. So no need to have 4 different tables.
But the problem is that I want the same form to register the TOOL data and HAMMER data (WRENCHES data...).
The user would fill in the TOOL fields and choose tool_type (saw, hammer, wrench or screwdriver), and depending on that type, only the fields that correspond to that type would be displayed (not the fields of all types as shown in the image).

01 relationship II.png

Now I have 5 tables: tool (field1, field2, tool_type), saw (fieldA, fieldB, fieldC), hammer (fieldD, fieldE), wrench (fieldF), screwdriver (fieldG, fieldH)
An 1 table with tool_type (with 4 rows: tool, saw, hammer, wrench, screwdriver) for de databasejoin element.

How can I implement these 0: 1 relationships in fabrik?

Thanks!!!
 
Last edited:
OK, then you could initially hide all the "tool-specific" fields on form load. And then display the needed fields when "tool type" element selection changes (with element javascript).

And to display the needed fields in the pre-filtered list, you can choose which elements to display in Fabrik list menu item settings.
 
OK, then you could initially hide all the "tool-specific" fields on form load. And then display the needed fields when "tool type" element selection changes (with element javascript).
Ok

And to display the needed fields in the pre-filtered list, you can choose which elements to display in Fabrik list menu item settings.
I can't understand that, what pre-filtered list?

Thanks!!
 
You can set the pre-filter in Fabrik list menu item settings to e.g. display only "Hammers" and there you can also choose which elements to display in the list. So when you have set the menu-item pre-filter to only show "hammers", you can also choose to display only the hammer-related fields in list.

It's in list menu item settings ->Fabrik List Options - > Show in list.

I can't understand that, what pre-filtered list?
 
But my first big doubt was how to implement those 5 tables in Fabrik so that when I add a row in TOOL, it is also added ONLY in the corresponding table (tool, saw, hammer, wrench, screwdriver). Is it enough to add the joins from the first diagram I attached? I'm afraid not. How should I do it?
 
I would do it like I described above with one table. But if you really want a separate table for every tool type, then why join at all. Just create a link "Add hammers" to "hammers" table, "Add wrench" to "wrenches" table etc.
 
It is not possible in a single table. Nor can I use multiple tables and add the record with a link. I need to do it as described in the form. I need to add the two records at the same time, a record in TOOL and another in the corresponding table (depending on the type of tool). It's not possible?
 
I don't understand your workflow.
But e.g. you can

join your lists,
  • set the joins repeat=yes, in the groups (tool-[saw] etc), set repeat-min=0 (so you won't get empty records if you don't add data), repeat-max=1, hide all repeat groups on load, show one group if the tool-type is selected, the user must click the + to add the tool data
  • or
  • set the joins repeat=no, hide all repeat groups on load, show one group if the tool-type is selected, remove empty records of the non-used tools via php plugin
or
add groups with elements for all tools to your tool table, hide groups on load, show if tool-type is selected, if you need the tool's data in extra tables you can copy the data via php or upsert plugin on save.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top