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

BaseModel - Add public getIdValue() method #4589

Merged
merged 1 commit into from
May 17, 2021

Conversation

najdanovicivan
Copy link
Contributor

@najdanovicivan najdanovicivan commented Apr 20, 2021

Description
This makes it possible to use protected idValue() method from outside of the model to get the id value of the entity.

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@MGatner
Copy link
Member

MGatner commented Apr 21, 2021

It would be great if we could find a way to deprecate the protected version and move towards this instead, but I don't know how to handle that with an abstract method.

@najdanovicivan
Copy link
Contributor Author

The only way we can introduce deprecation is to make the abstract idValue() method deprecated. Then we change in all places to use getIdValue() instead.

After that we change getIdValue() to also be abstract function and implement in the Model class. the old idValue() method will just pass the call to getIdValue() so for some time we'll have both methods available. In any case it will be breaking change as introducing new abstract method in BaseModel will require the method to be implemented in all child classes

@MGatner
Copy link
Member

MGatner commented Apr 22, 2021

Understood! Please add a note to the User Guide changelog about this new function - we can handle deduplicating in version 5.

@najdanovicivan
Copy link
Contributor Author

@MGatner I'll add the deprecation and modify the existing model to use the new method

@najdanovicivan
Copy link
Contributor Author

najdanovicivan commented Apr 22, 2021

If I am to add a new method in the interface it will be BC in any case. Since all the custom models will have to be updated anyway

So for now we can leave the getIdValue() with existing implementation calling the protected idValue() from baseModel(). An override can be added in the model classes to implement the new feature

@najdanovicivan
Copy link
Contributor Author

I've found a way on how to do deprecation without introducing a BC. The only issue that I have to define both methods in base model.

The only downside of this approach is that any of those methods won't be forced to be defined in the model class. And if there is no single of them defined the infinitive loop will occur.

@MGatner
Copy link
Member

MGatner commented May 9, 2021

I'd rather have the duplicate method than the side effects you notes. Can you revert to abstract and resolve merge conflicts? Then I think this is good.

@MGatner MGatner merged commit e3b5232 into codeigniter4:develop May 17, 2021
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.

2 participants