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

Expose hasPrimaryKey method in Table object #1979

Merged
merged 1 commit into from
Jun 2, 2021
Merged

Expose hasPrimaryKey method in Table object #1979

merged 1 commit into from
Jun 2, 2021

Conversation

MasterOdin
Copy link
Member

This adds a new method to the Table object to allow checking for the existence of a primary key. This mirrors the existing hasForeignKey function on the object.

Signed-off-by: Matthew Peveler <matt.peveler@gmail.com>
@MasterOdin
Copy link
Member Author

@dereuromark I guess the ideal way to add a test for this would be to do something like:

public function testHasPrimaryKey() {
    $mock = $this->createMock(AbstractAdapter::class);
    $mock->expects($this->once())->method('hasPrimaryKey')->with('test', 'col', null)->toReturn(true);
    $table = new Table('test', [], $mock);
    $this->assertTrue($table->hasPrimaryKey('col'));
}

The adapters themselves have tests for hasPrimaryKey so probably don't need to replicate that logic here. Thoughts?

*
* @return bool
*/
public function hasPrimaryKey($columns, $constraint = null)
Copy link
Member

Choose a reason for hiding this comment

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

You could add a type for the 2nd param it seems. Same for return value

Copy link
Member Author

Choose a reason for hiding this comment

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

I would not want to add type hinting to just one function in this file for fear of overall consistency. Perhaps on a release of 0.13, could do a quick release of 0.14 which just adds type hints where possible across the entire codebase, and then going forward type hints are always used?

Could also land such work in 0.13, but I'd almost at this point just say I'll get back to and land #1962 and then release instead of having it drag out too much longer.

Copy link
Member

Choose a reason for hiding this comment

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

Consistency sure is a point.
But this is a new public API method that is added.
And I think the benefits of types in place weigh higher than the consistency argument (from user perspective anyway).
I agree that any 0.13 semantic major release would need to clean up all possible types.

@dereuromark dereuromark added this to the 0.12.x milestone May 17, 2021
@dereuromark dereuromark merged commit 7afa641 into cakephp:master Jun 2, 2021
@MasterOdin MasterOdin deleted the has_primary_key branch June 2, 2021 11:21
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