Keeping frontend data without duplication

I have my doubts about the path I am following, thus this question. Background Consider data which have forth and back references (many to many) -- examples being authors can write multiple books, and books can be written by multiple authors. Actors can play in multiple movies, and movie cast consists usually of multiple actors. And so on. Frontend fetches say a page of data, and then you can edit it. Keeping the first example, you can add another book to author. His/her book count increases, fine. But you could target a book which is listed, and add author there. If the author was on the displayed list, his/her book references should be updated also, as well book count. So this is why data instance should be singletons (without duplication). If the data was duplicated, editing book would not update the author (because Author-with-books would be one instance, and Book-having-this-author would be another instance). Problem I have more and more data categories, and I realized I would need some data manager, which sole purpose would be to track instances, and for example, if I fetch few more records from the database, it would make sure the existing data and the incoming should be unified (in case of duplicates). Technically I have no problems with implementing this, I am somewhat surprised I need data manager for seemingly trivial task, which triggered my doubts if this is right approach, and maybe I am reinventing the square wheel. So, am I on the right track?

Feb 12, 2025 - 11:03
 0
Keeping frontend data without duplication

I have my doubts about the path I am following, thus this question.

Background

Consider data which have forth and back references (many to many) -- examples being authors can write multiple books, and books can be written by multiple authors. Actors can play in multiple movies, and movie cast consists usually of multiple actors. And so on.

Frontend fetches say a page of data, and then you can edit it. Keeping the first example, you can add another book to author. His/her book count increases, fine. But you could target a book which is listed, and add author there. If the author was on the displayed list, his/her book references should be updated also, as well book count.

So this is why data instance should be singletons (without duplication). If the data was duplicated, editing book would not update the author (because Author-with-books would be one instance, and Book-having-this-author would be another instance).

Problem

I have more and more data categories, and I realized I would need some data manager, which sole purpose would be to track instances, and for example, if I fetch few more records from the database, it would make sure the existing data and the incoming should be unified (in case of duplicates).

Technically I have no problems with implementing this, I am somewhat surprised I need data manager for seemingly trivial task, which triggered my doubts if this is right approach, and maybe I am reinventing the square wheel. So, am I on the right track?