#Pivot 3 tables - JSON returning duplicate data
11 messages · Page 1 of 1 (latest)
I'd suggest that you maybe remove that package trait, I don't think you'll have a problem eagerly loading data in Laravel if your relationships are setup correctly. That's what my gut is telling me anyway.
Oh - so your getting 3 results back there because it's found 3 regional releases. Isn't that correct if you're looking for that within each dataset
I think you might have better luck trying to first retrieve the game and it's platform first. This should give you a nice slice of data. You then have multiple ways of asking for the regions of release or at least is should be easier to see where that data should be tied too. I think you might need to look for it further down a chain rather than trying to use it in the same breath of asking for game and platform. More like game->platform->releases although it's difficult to know exactly what it all looks like.
Maybe if you shared the table schema (rough visual of something like what you shared for https://medium.com/@kaism/3-way-pivot-table-in-laravel-d42d60462b06) At least you might get people far more proficient than myself jumping on on this to advise
@wispy burrow Just wondering something so I can get it clear in my head: does a game have a region or does a platform have a region?
Ah - I think I see, it has to be tied to both
I think it's this structure you need https://laravel.com/docs/9.x/eloquent-relationships#has-many-through
A pivot table I think should only pivot from 1 point which is why I think you're getting the results in the way you are.
I think this might be more of a logic chain (I made that expression up so I wouldn't google it lol). If you look at the Laravel docs I linked you'd just need to replace projects for games, environments for platforms and deployments for regions.
Maybe, it's difficult to know just looking at it
I feel like that's the right way to go, my brain breaks down when it's 3 or more dimensions 😂
Relationship between games->platforms (one->many)
Relationship between games->platform->regions (one->(through)->many)
I hope I'm advising you right, this stuff is always suck-it-and-see with me rather than ever being sure from the outset
Oh I was talking about the relationship between games only when I mentioned them relationships
Relationship between games->platforms (one->many)
Relationship between games->platform->regions (one->(through)->many)
But yes;
platform->games (one->many) (game belongsTo platform && platform hasMany games)
region->platforms (one->many) region belongsTo platform && platform hasMany games)
game->platform->regions (one->one->many) (region belongsTo plaform && game has many regions through platform (hasManyThrough))
@wispy burrow