cakephp / elastic-search

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

No callbacks are called #84

Closed dario86 closed 8 years ago

dario86 commented 8 years ago

Hi, I have this code in my controller:

public function formStupido()
{
        $Companies = TypeRegistry::get('Companies.Companies');
        $companies = $Companies->newEntity(['name' => 'ciao']);
        $savedCompany = $Companies->save($companies);
}

This is my CompaniesType in plugin Companies:

<?php
namespace Companies\Model\Type;

use Cake\ElasticSearch\Type;
use Cake\ElasticSearch\Query;
use Cake\ElasticSearch\FilterBuilder;
use App\Lib\FileUpload;

class CompaniesType extends Type
{
    /**
     * initialize method
     * 
     * @param array $config
     */
    public function initialize(array $config)
    {

    }

    public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options)
    {
        debug('marshaller');
        exit();
    }

    public function beforeSave(Event $event, ArrayObject $data, ArrayObject $options)
    {
        debug('before');
        exit();
    }
}
?>

Document is created and no callbacks are called

damianoporta commented 8 years ago

same here!

josegonzalez commented 8 years ago

@markstory I know you're not a fan of adding behavior support because some behaviors may be incompatible, but couldn't the same thing be said about a behavior targeting a specific database? For instance, I could write something that targeted a specific column type only available to postgres. I don't see why we can't put a big fat caveat on this plugin and say certain core behaviors are not expected to work (or make them work).

markstory commented 8 years ago

I don't see why we can't put a big fat caveat on this plugin and say certain core behaviors are not expected to work (or make them work).

Outside of the TimestampBehavior, I'm not sure any of the core behaviors work.

markstory commented 8 years ago

Looks like we never implemented the default callback binding, for Type. I'll add that in.

josegonzalez commented 8 years ago

@markstory how difficult would it be to test that? Why do you think they wouldn't work?

markstory commented 8 years ago

Pull request up now.

markstory commented 8 years ago

@josegonzalez I don't think the others would work based on how they are implemented. TreeBehavior, CounterCache and TranslateBehavior rely on association methods that do not exist in elasticsearch.