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

May be true for EntityTrait::has('exist_empty_property') #8494

Closed
kanonji opened this issue Mar 19, 2016 · 4 comments
Closed

May be true for EntityTrait::has('exist_empty_property') #8494

kanonji opened this issue Mar 19, 2016 · 4 comments
Assignees
Milestone

Comments

@kanonji
Copy link

kanonji commented Mar 19, 2016

I think there is a mismatch between doc block and code in EntityTrait::has()

/**
 * Returns whether this entity contains a property named $property
 * regardless of if it is empty.
 *
 * ### Example:
 *
 * ```
 * $entity = new Entity(['id' => 1, 'name' => null]);
 * $entity->has('id'); // true
 * $entity->has('name'); // false
 * $entity->has('last_name'); // false
 * ```

https://github.com/cakephp/cakephp/blob/master/src/Datasource/EntityTrait.php#L318-L329

The Example in doc block is correctly expressed actual behavior.
But head of doc block is different.

$entity->not_associated; // property is not exists.
$entity->associated_has_one_but_no_record; // there is a property but null

I want discriminate two cases above with EntityTrait::has().
I guess this is one of the reasons EntityTrait::has() is implemented.
Or could it be that head of doc block is wrong?

Expected Behavior

$entity = new Entity(['id' => 1, 'name' => null]);
$entity->has('name'); // true

Actual Behavior

$entity = new Entity(['id' => 1, 'name' => null]);
$entity->has('name'); // false

@lorenzo
Copy link
Member

lorenzo commented Mar 19, 2016

The current behaviour is the intended behaviour. I agree there is a need fo another method to check he presence of a field, regardless of its value.

@kanonji
Copy link
Author

kanonji commented Mar 19, 2016

hmm...Do I misunderstand the first sentence in the doc block?
But anyway I'm glad if CakePHP has another method.

@markstory markstory added this to the 3.2.6 milestone Mar 19, 2016
@markstory
Copy link
Member

I think the use of 'empty' is confusing here. As 'empty' means something very specific in PHP which this method is not doing. I can change up the wording to be less confusing.

@markstory markstory self-assigned this Mar 19, 2016
markstory added a commit that referenced this issue Mar 22, 2016
Reflect how the code actually works.

Refs #8494
@markstory
Copy link
Member

Pull request up now.

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

No branches or pull requests

3 participants