FriendsOfCake / crud

Production-grade rapid controller development with built in love for API and Search

Home Page:https://crud.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CrudComponent::table() should support non-table model types

asgraf opened this issue · comments

commented

ModelAwareTrait (which provide loadModel()) has been deprecated since Cake 4.3 and dropped in 5.0. So there's no point in making change for this now for a deprecated feature.

How should i use Endpoints from muffin/webservice with crud & crud-view then?
I don't see any non deprecated way.

commented

I don't see any non deprecated way.

There isn't any. Webservice plugin and Crud support for it will have to be re-thought for working without the deprecated features.

If removing the return type for CrudComponent::table() is enough for you currently then we can do that.

I think CrudComponent::table() should under the hood just call ProxyTrait::_table() of the current action class.
How ProxyTrait::_table() will be modified under cake5 branch is matter for another ticket.

commented

Why do need to use CrudComponent::table()? You can directly use $this->loadModel() in your controller. Within the plugin CrudComponent::table() is only used by CrudComponent::entity() which isn't used anywhere in the plugin and in your controller you can just use $this->loadModel()->newEntity(). So these component methods are pretty much redundant.

Some of my controllers work with Tables and some with Endpoints
Currently i have following code in my AppController:

if ($this->getModelType() === 'Table') {
    $repository = $this->fetchTable();
} else {
    $repository = $this->loadModel();
}

It would nice to replace it with:

$repository = $this->Crud->action()->_table();//protected - does not work

or with something like

$repository = $this->Crud->table();

To get same repository as current action uses.

This would be more clean code without direct calling of any deprecated functions from my app
(i know that under the hood deprecated loadModel function will be still be called but i assume that this will change in the future to maintain further interoperability between crud and webservice plugins and cakephp 5.x)

commented

Since you need to use loadModel() one way or the other just keeping using that even for tables.

5.x is a different story. Will have to see how to update the Webservice plugin to work without the ModelAwareTrait and then look into supporting it with Crud.

After last changes in cakephp 5.x all loadModel calls can be simply replaced with fetchModel calls

commented

Yes, would you like to submit a PR for the cake-5 branch?