cakephp / elastic-search

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

Virtual Properties not working since 2.0 #192

Closed agarzon closed 5 years ago

agarzon commented 5 years ago

Cake\ElasticSearch\Document is extended from Cake\ORM\Entity so in theory it should be possible to use Virtual Properties.

In my case Virtual Properties was working pretty well in the previous versions of this plugin. However since upgraded to 2.0 it stop working and there's no more Virtual Properties

https://book.cakephp.org/3.0/en/orm/entities.html#exposing-virtual-properties

Cake someone else confirm this? easy test:

 protected $_virtual = ['fake']; // Expose the virtual property

    protected function _getFake()
    {
        return 'This is fake data;
    }

You should see that new property fake in your entity (document)

BTW the cakephp documentation still mentioning Cake\ElasticSearch\Type even when that is no longer available and replaced for Cake\ElasticSearch\IndexRegistry

https://book.cakephp.org/3.0/en/elasticsearch.html#getting-type-instances

agarzon commented 5 years ago

Finally I know now where the problem is. After dozens hours testing and failing, debugging, etc.. :tired_face:

You REALLY need the Index class even with absolutely nothing. Mine now is just like:

<?php
namespace App\Model\Index;

use Cake\ElasticSearch\Index;

class TournamentsIndex extends Index
{

}

And now I have all my properties including the virtual ones... The documentation really need some love :hearts: :wink:

I guess this issue can be closed, but if any contributor thinks it must be keep opened for reference or future development, feel free to reopen it.

lorenzo commented 5 years ago

@agarzon maybe send us a PR with some documentation updates? <3