vendredi 16 octobre 2015

Laravel Relationships Game -> 2 decks

I have two tables, one table stores decks (ie. a deck of cards), the other table, called games, stores a game. The game table stores the id of the deck that I have used, and also the deckId of the opponent.

So, 2 records in the game table might look like :

id player_deck_id    opponent_deck_id  result
-----------------------------------------------
1 | 4              |   5              | win
2 | 4              |   4              | win

2 records in the deck table might look like:

id   label
----------------------
4 | testDeck
5 | anotherDeck

I have two Models, one Deck and one Game Model, is there any way to set up oneToMany relation between a game and decks? As in, one game hasMany (2) decks. I know I can set a oneToMany Relation on a Deck, as in, one Deck hasMany Games, but, other than manually programming it, is there any way to retreive both Decks for a Game utlizing the relationship functionality (so I don't have to rewrite the whole lazy loading, eager loading etc...)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire