cakephp / elastic-search

Elastic search datasource for CakePHP
Other
88 stars 53 forks source link

Exception: doc id not found #129

Closed angelxmoreno closed 7 years ago

angelxmoreno commented 7 years ago

Is it expected to get an exception when i try to fetch a non-existing doc?

public function indexToEs(EntityInterface $entity)
    {
        $entity_clone = clone $entity;
        unset($entity_clone->body);

        $items_table = TypeRegistry::get('Items');
        $found = $items_table->get($entity->id); //exception thrown

        if ($found) {
           $indexed = $items_table->patchEntity($found, $entity_clone->toArray());
        } else {
            $indexed = $items_table->newEntity($entity_clone);
        }

        if (!$items_table->save($indexed)) {
            var_dump($entity_clone->getErrors());
        }
    }
lorenzo commented 7 years ago

Yes, it is expected when using the get function. you can use find($conditions)->first() instead

angelxmoreno commented 7 years ago

seems to lack cake-orm behavior but good to know!

ADmad commented 7 years ago

This is the same behavior you would get when using Cake\ORM\Table::get() too.