Mix data from api with entites from the DB


Do you have some hint for me for the following situation:

Consider an user having some profile data. Some of this data should come from an api (like name, birthday) and some not (user editiable). The data from the api MUST NOT be persisted in the database or stored anywhere nor is it editable by user himself.

But this data should be mixed in normal finders, so as they are in the database itself. So all finders getters work with this data as expected.

I think best will be to inject this data on the lowest level to make CakePhp think it will come from the DB?

But where and how?

CakePHP 3.7


My first thought would be creating your own data-source implementing \Cake\Datasource\RepositoryInterface. I’ve done that in the past, but never to keep complex find or association going. If I’m fine with a cheap implementation maybe I’m just adding some functionality to the user entity. Not sure, depends on the details.

I’m not sure what is API data, but I think: php unset() before save.