mardi 1 mai 2018

Laravel Eloquent populates collection with id 1 always

I have a project on laravel 5. I wrote an SQL to select games from database, and after executing it, I got models collection, where every model has id = 1.

This is my query:

select * from `games` left join `game_vendors` on `games`.`vendor_id` = 
`game_vendors`.`id` where `game_vendors`.`name` != 'some_vendor' and 
`games`.`id` not in (1,2,3,4,5,6,7,8,9,10,11,12);

checked this query in mysql terminal - all is fine, id's are correct, but on postman or in the browser, I got this

array(2021) {
  [0]=>
  array(32) {
    ["id"] => int(1)
  [1]=>
  array(32) {
    ["id"] => int(1)
  ...
  ...
  ...
  [24]=>
   array(32) {
    ["id"] => int(1)

Model class contains this:

class Game extends Model {
protected $table = 'games';

public function vendor()
{
    return $this->hasOne('App\GameVendor', 'vendor_id', 'id');
}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2FwJGzx
via IFTTT

Aucun commentaire:

Enregistrer un commentaire