Skip to content

Conversation

@ADmad
Copy link
Member

@ADmad ADmad commented Nov 13, 2025

Calling behavior methods directly on the table instance is deprecated in CakPHP 5.3

Calling behavior methods directly on the table instance is deprecated in CakPHP 5.3
@ADmad ADmad added this to the 7.x milestone Nov 13, 2025
@ADmad ADmad merged commit 758ea82 into master Nov 13, 2025
7 checks passed
@ADmad ADmad deleted the ADmad-patch-1-1 branch November 13, 2025 06:11

// Setup search filter using search manager
$this->searchManager()
$this->getBehavior('Search')->searchManager()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But isnt that then executed always? Whereas the current searchManager() is only executed once you actually invoke it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main concern is the length of initialize() though.
It often already is a lot of lines long for all the relation setup and behavior adding and more.
This adds also the whole search config into it.

So the extra method wasnt too bad after all in terms of readability of the code.
It seems the only alternative really is then to use the collections?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found out:

Additionally, it breaks all usage of dynamic attachment if one is forced to to abandon this method:

$this->Users->addBehavior('Search.Search');

wouldnt work anymore, so far did by using the method when needed.

Copy link
Member Author

@ADmad ADmad Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But isnt that then executed always?

In the updated example, the $this->searchManager() call was also from table's initialize() so it too was executed always.

My main concern is the length of initialize() though.

Yes that's a concern, that is why filter collections were added.

it breaks all usage of dynamic attachment

Yes it does, the solution is to use filter collections. In general I don't think configuring tables from outside is a good idea.

Anyway, we can undo the deprecation of searchManager() on table classes if you prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make it a soft deprecation for now, this wouldnt make all CI builds report it right away, and people have time to migrate.
This was a patch release after all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a patch release after all.

It was 1st patch release of a new minor :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides there's no noticeable way to soft-deprecated this feature as it's a methods that's added to the table class, so we can't have any deprecation annotation for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its visible in the IDE (strike though), that could be enough for the time being IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how to achieve that? As I said this is a method added to app code, not the plugin itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right..^^

ADmad added a commit that referenced this pull request Nov 19, 2025
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

Successfully merging this pull request may close these issues.

3 participants