cakephp / elastic-search

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

Fixes/honour hydration options of embeds #184

Closed lilHermit closed 6 years ago

lilHermit commented 6 years ago

Allows for multi level embedding whilst marshalling via one/many if associated is provided. Also supports the associated param with options so you can limited the hydration via accessibleFields.

For example

        $data = [
            'address' => '123 West Street',
            'remove_this' => 'something',
            'users' => [
                [
                    'first_name' => 'Mark',
                    'last_name' => 'Story',
                    'user_type' => [
                        'label' => 'Admin',
                        'level' => 21
                    ]
                ],
                ['first_name' => 'Clare', 'last_name' => 'Smith'],
            ]
        ];
        $options = [
            'accessibleFields' => ['remove_this' => false],
            'associated' => [
                'User' => [
                    'accessibleFields' => ['last_name' => false],
                    'associated' => [
                        'UserType' => [
                            'accessibleFields' => ['level' => false]
                        ]
                    ]
                ]
            ]
        ];

        $marshaller = new Marshaller($index);
        $result = $marshaller->one($data, $options);
josbeir commented 6 years ago

I like this, started on something similar but stopped developing on in due to a change in my project that did not require it anymore.

Does it work correctly with nested validation contexts ?

lilHermit commented 6 years ago

@josbeir I haven't tested validation but feel free to test. This only works with Marshaller not when pulling from the index

lorenzo commented 6 years ago

@lilHermit I'll merge once you and @josbeir figure out if validation is a problem :)

josbeir commented 6 years ago

I'm ok with a merge as nested validation is an edge case and there are tests in place that should do basic checking on this, as these or not failing i'm currently not seeing an issue :-)

lilHermit commented 6 years ago

I'll add some tests in a different PR for nested validation