php - Laravel relationship structure -


i have table of fixtures looks this;

  • user_id
  • opponent_id
  • gameweek
  • league_id

i have results table stores result of fixture , when come in.

  • user_id
  • gameweek
  • league_id
  • result

what struggling relationship between 2 , how call relationship when need it.

essentially, each fixture contains 2 results; 1 user_id_result , 1 opponent_id_result (both of refer id in users table)

i did in fixture model;

public function userresult() {     return $this->hasmany('app\models\result', 'league_id', 'league_id')         ->where('user_id', $this->user_id)         ->where('gameweek', $this->gameweek); } 

and, although worked, don't think it's quite right , did not work when called through eager loading.

thanks guys.

this doesn't seem database structure root of problem lies. both tables have 3 columns same thing. not inefficient confusing.

at first glance, make more sense drop 3 columns in results table, user_id, gameweek , league_id , replace them fixture_id handle relation. fixtures.id = results.fixture_id.

i don't know what's being stored in this, it's possible simplify further dropping results table , adding results column onto fixtures table. let null , when game done, update column.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -