apokall
6 months ago

Dont get relation if add orderBy and Take\Limit

Posted 6 months ago by apokall
User::with(['playerGames' => function($query) {
            $query->whereDate('created_at', now());
            $query->where('status', PlayerGame::PLAYER_GAME_STATUS_FINISHED);
//          $query->select(['id', 'winner']);
//          $query->orderBy('created_at', 'desc');
            $query->take(21);
        }])->get()

All hello! I have some problems and two questions:

  1. Why i dont get any relation records in my user model if i uncomment "$query->orderBy('created_at', 'desc');"
  2. Why i dont get any relation records in my user model if i uncomment "$query->select(['id', 'winner'])"

I tried different combinations already, but they do not help me. If I remove take \ limit but leave ordeBy\ lastest then records will appear in my user model. Please help anyone who encountered a similar problem when loading Eager.

Please sign in or create an account to participate in this conversation.