Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
asgraf opened this issue Jan 11, 2023 · 9 comments
Open

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

asgraf opened this issue Jan 11, 2023 · 9 comments

Comments

@asgraf
Copy link

asgraf commented Jan 11, 2023

@asgraf asgraf changed the title CrudComponent::table() does not support model types CrudComponent::table() should support non-table model types Jan 11, 2023
@ADmad
Copy link
Member

ADmad commented Jan 11, 2023

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.

@asgraf
Copy link
Author

asgraf commented Jan 11, 2023

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

@ADmad
Copy link
Member

ADmad commented Jan 11, 2023

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.

@asgraf
Copy link
Author

asgraf commented Jan 11, 2023

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.

@ADmad
Copy link
Member

ADmad commented Jan 11, 2023

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.

@asgraf
Copy link
Author

asgraf commented Jan 24, 2023

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)

@ADmad
Copy link
Member

ADmad commented Jan 24, 2023

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.

@asgraf
Copy link
Author

asgraf commented Apr 12, 2023

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

@ADmad
Copy link
Member

ADmad commented Apr 12, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants