Accepting Suggestions on how to relation my entities
Question

Hello.

First I would like to explain my goal.

I have an entity called Machines. To each Machine I will assign one SerialNumber, one Model, one Screw Size and up to 16 Options. I also have dates, display and schematic status but that's not relevant for the question.

  • Note 1: It's important to know that I have now 16 options, BUT in the future it could be more. I have a page where I can manage the options, create, delete, etc.
  • Note 2: I also have a page where I can create more models, screw sizes.

With this said I'm know showing my Entities Diagram:

My Machine details page:



My Machine List Page:


So the easier thing to do, was to create all 16 option inside Machine Entity. That way, everytime I create/update a machine I just have to select the options I want.

The problem is that using that approach, but option will be static.

So I have a MachineOption Entity that assigns one Option ID to a Machine ID, so that way one Machine can have multiple options.

Problem 1: 

  • Below Options Dropdown (Machine details page), I show a list if the options selected. When I press save I send that list to a server action. 
  • When a user wants to update a machine I fetch the info from aggregate, use a ListAppend, and show that list to the user.
  • After user add 1 or 2 more options I send that list to server action in order to save, but my list will now be filled with new options and older options which give me error when I try to save. I already have indexes to prevent duplicates creation.
  • I don't have a ListDistinct server action. Do I need to do it using 2 For Each to each list and create a Aux List without the duplicates?

Problem 2: 

  • I want my options to be dynamic. So if I have 16 options available I want those 16 columns on my Machine List page so a user can check which options the machine have.
  • If I increase my options I do have to manually create another column or there is a way to show another column on the table?

Am I overcomplicating this?

Thanks in advance.


mvp_badge
MVP
Solution

Hi SirT,


For problem 1, a simpler option is to bulk delete the options of that Machine and insert the list.

So if you're editing a machine with option #1 and #2 and now they should have option #2 and #3, you will be deleting #1 and #2, and (re)inserting #2 and #3.


For problem 2, you can do a query from your Options With or Without MachineOptions joining by option id and MachineOptions.MachineId = MachineId. This will guarantee that you will always show all the options and with the value filled if that option exists for that machine.


Kind Regards,
João

Thanks for the answer João.

For problem 1 :

I guess that it is way simpler to do it like that, as opposed to work with a List and Aux List and filter them.


For problem 2 what I mean is:

  • For this example think that I only have two options available. So my Table columns names match just like the on my initial post.
  • IF I create two more options, the values will be available to query from the aggregate, but my columns on the table on that page will still be same.
  • I will have to manually create two more header cell for Option 3 and Option 4, and then add the Expression value to the cells.

Am I wrong?

mvp_badge
MVP

Hi SirT,


I misunderstood your problem #2, you want to have "dynamic columns" in your table, a column per each option, right?


That's not a simple case and I would suggest to consider if this is really needed.

In any case you can do it with a bit of creativity. The way I would do it would be to query the database and create a JSON string with a column for each option and then use the Data Grid Reactive forge component. This component turns the JSON into a table with "excel-like" features. It includes a demo and a comprehensive documentation on how to use it.


I had used it recently successfully for this use case but as I mention it is an advanced scenario and I would first question the value against  the effort before going for it.

Thanks once again. 

That's really the question. I was already questioning the value against the effort. The options are bit of a static Entity but I still wanted to give it some room.

After this afternoon I guess I will maintain as it is, fixed columns. If in the future I need to create more columns, I will create it manually.

Thanks.

mvp_badge
MVP

It's all a matter of your requirements and if your options need to be changed in run time. If they do, it can't be a static.

In any case, the dynamic columns is possible with the method I mentioned, it just takes a bit of work to prepare the JSON string and that's it.

In case the answer provided helped you solve your problem, consider marking it as a solution so others with the same question can also find the help they need.


Kind Regards,
João

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.