Laravel 5.6 - Making Direct/Indirect Relationships Structure Between Entries

Status
Not open for further replies.

Tennouji

Active Member
569
2012
62
95
The core issue I'm having isn't exclusively laravel-related, but since I just started learning laravel a few days ago I'm stating the framework just in case there already is a specific solution for this.

What I'm trying to do is making direct relationships between entries in the same model.

e.g. Entry B is a sequel of Entry A, and Entry A is a prequel of Entry B

Next, I wanted is to have relationships to have a two-way reference between each entries. Reciprocally, if I remove the relationship in one entry, it should update and remove the reciprocal relationship the other entry had.

e.g. If I set Entry B to be a sequel of Entry A, it should automatically set Entry A to be a prequel of Entry B as well. If I remove Entry B as a sequel of Entry A, it should automatically remove Entry A as a prequel of Entry B as well.

Thirdly, I also want one Entry to be able to query all other indirect relationships it has, at multiple levels/layers.

e.g. If Entry A have Entry B as its sequel, and Entry B has Entry C as its sequel, and Entry C has Entry D as its sequel as well, then Entry A should be able to directly refer to Entry B as it's sequel, and refer Entries C and D as its indirectly related entries.

Finally, I wanted to have different types of these two-way direct relationship references.

Prequel <=> Sequel
Full Story <=> Summary
Parent Story <=> Side Story
Same Setting <=> Same Setting
Alternative Setting <=> Alternative Setting
Alternative Version <=> Alternative Version
Other <=> Other

This concept isn't new since I'm actually trying to imitate AniDB's own relationship structure. I'm thinking that the direct relationships should be their own separate model and db tables, then I'll just query them in the entry model via a one-to-many relationship.

The problem is I am having a difficult time on deciding about the structure it should have. I made this thread so that I can hear everyone else's suggestions/opinion about it.
 
3 comments
Thanks a lot for the link. I knew that I'll be needing to dive deeper into the relationships of models, but the illustrations in the link you provided is a huge help for me.
 
Status
Not open for further replies.
Back
Top