babenkoivan / elastic-migrations

Elasticsearch migrations for Laravel
MIT License
189 stars 32 forks source link

Trying to get property 'batch' of non-object in Repositories\MigrationRepository.php:53 #29

Closed vishaltomar76 closed 3 years ago

vishaltomar76 commented 3 years ago

I have 2 existing indexes in elastic search and i have written another migration for 3rd index then it give me the below error when i am trying to run the "php artisan elastic:migrate"

Trying to get property 'batch' of non-object in Repositories\MigrationRepository.php:53 When i try to debug it the i found..... $record = $this->table() ->select('batch') ->orderBy('batch', 'desc') ->first(); return isset($record) ? (int)$record->batch : null;

   Here "$record" variable contain the array not the object. I am using mongoDB as primary database 
   Please fix this issue asap and let me know if you need any further information about this issue 
babenkoivan commented 3 years ago

Hi @vishaltomar76, what library do you use for MongoDB? According to the Laravel first method definition, it shouldn't return an array:

/**
 * Execute the query and get the first result.
 *
 * @param  array|string  $columns
 * @return \Illuminate\Database\Eloquent\Model|object|static|null
 */
public function first($columns = ['*'])
{
    return $this->take(1)->get($columns)->first();
}
vishaltomar76 commented 3 years ago

Hello @babenkoivan I am using the below library for MongoDB https://github.com/jenssegers/laravel-mongodb

vishaltomar76 commented 3 years ago

Everywhere I used the first() method it returning the object... but only the above case it returning array don't know why...

babenkoivan commented 3 years ago

Hey @vishaltomar76, I'll need your help with this. Can you maybe share what exactly $record contains? If it's an array, then please open an issue in https://github.com/jenssegers/laravel-mongodb, because it violates Laravel's first method definition.

vishaltomar76 commented 3 years ago

Hey @vishaltomar76, I'll need your help with this. Can you maybe share what exactly $record contains? If it's an array, then please open an issue in https://github.com/jenssegers/laravel-mongodb, because it violates Laravel's first method definition.

Yes, $record contains an array. If i am applying Model query with first method then it always return object but if I use the DB Query builder then it returning array. Why you are using DB query? You can also replace it by Model query then it will work fine

babenkoivan commented 3 years ago

Hey @vishaltomar76, please open an issue in the https://github.com/jenssegers/laravel-mongodb repository. I'm pretty sure it uses the BuildsQueries trait and doesn't respect the definition of the first method:

/**
 * Execute the query and get the first result.
 *
 * @param  array|string  $columns
 * @return \Illuminate\Database\Eloquent\Model|object|static|null
 */
public function first($columns = ['*'])
{
    return $this->take(1)->get($columns)->first();
}
github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days