CROSP
CROSP

Reputation: 4617

Laravel Eloquent model duplicate keys in model

I cannot figure out what is the problem, I cannot remember when it firstly appeared, it doesn't make a lot of problems now, but it wastes connection and this is not last point in mobile communication. The problem is following.

Here is output of model, such output is for any model, I mean it duplicates each associative value with index.

array:1 [
  0 => array:12 [
    "id" => "55"
    0 => "55"
    "user_id" => "199"
    1 => "199"
    "token" => "b7351fb13c5ce06a6f09ef6147c7d7d5"
    2 => "b7351fb13c5ce06a6f09ef6147c7d7d5"
    "expiration_time" => "1452795403"
    3 => "1452795403"
    "scope" => "0"
    4 => "0"
    "last_login_time" => "1452194400"
    5 => "1452194400"
  ]
]

I have tried to follow the stack of function call and stopped at

public static function hydrate(array $items, $connection = null)

The I got here dump as I described above.

I have no idea what can cause such behavior.

Maybe someone has idea what can cause such problem. Thanks everyone.

EDIT

I have uploaded code to pastebin http://laravel.io/bin/VP435

I edited model for my needs, but it shouldn't affect this part.

I am trying to find the "root of evil" right now.

hybrate method is called by Builder

public function getModels($columns = ['*'])

This is query to DB $results = $this->query->get($columns);

Query is following

"select * from `tokens` where `token` = ? limit 1"

And it is correct request no issue with it

Upvotes: 0

Views: 667

Answers (1)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111899

Please make sure that in config/database.php you have set fetch to PDO::FETCH_CLASS and not to PDO::FETCH_BOTH.

By default it's PDO::FETCH_CLASS and it seems you have somehow set it to PDO::FETCH_BOTH.

If it's not the case, show example how you get this object.

Upvotes: 2

Related Questions