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

"Notice: Undefined offset: 0" when there is no ID Column defined #6412

Closed
wants to merge 2 commits into from

Conversation

JarJak
Copy link
Contributor

@JarJak JarJak commented Apr 25, 2017

When you forget about defining the ID/PK Column, then this ugly Notice appear.

This PR is not ready for merge, but shows where the problem exist.

Could you fix this or tell me the way this Pull Request would be acceptable? Thanks.

How to reproduce?
Remove ORM\Id annotation, then try to regenerate entities.

@Ocramius
Copy link
Member

@JarJak metadata without identifier isn't really valid metadata - is this for an embeddable? Can a test be added?

@JarJak
Copy link
Contributor Author

JarJak commented Apr 25, 2017

@Ocramius I agree that metadata without identifier is invalid, however if you throw nice Exception than this Notice, then this mistake would be much easier to debug and fix.

I will add test later.

When you forget about defining the ID/PK Column, then this ugly Notice appear.
Now it will throw nice Exception.
@JarJak
Copy link
Contributor Author

JarJak commented Apr 27, 2017

@Ocramius I've updated PR with two nearly identical tests (I don't know where exactly I should put my test, so I've created them in 2 places). This change might be a BC Break if someone has error reporting turned off (before it would silently fail instead of throwing an exception), however since master even switched to PHP7 I think this minor BC Break wouldn't be a problem.

*/
public static function noIdDefined($entity)
{
return new self('No ID defined for entity '.$entity);
Copy link
Member

Choose a reason for hiding this comment

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

Please add spaces before and after the concatenation operator ('No ID defined for entity ' . $entity)

/**
* @author JarJak
*/
class DDC6412Test extends OrmTestCase
Copy link
Member

Choose a reason for hiding this comment

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

I'd say it's better to leave this check in ClassMetadataTest.php only, then we keep it together with the other mapping assertions

@@ -1803,6 +1803,10 @@ public function getSingleIdentifierFieldName()
if ($this->isIdentifierComposite) {
throw MappingException::singleIdNotAllowedOnCompositePrimaryKey($this->name);
}

if ( ! isset($this->identifier[0])) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you also mention this change in the docblock? We currently have @throws MappingException If the class has a composite primary key. but would be good to say something like @throws MappingException If the class doesn't have an identifier or it has a composite primary key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@lcobucci
Copy link
Member

This change might be a BC Break if someone has error reporting turned off

@JarJak It's not really considered a BC Break since we already expected that type of exception. It was actually something that we missed. Thanks for addressing it 😉

@JarJak
Copy link
Contributor Author

JarJak commented Apr 29, 2017

@lcobucci I polished the code according to your tips, thanks :)

Copy link
Member

@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

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

LGTM I'll just rebase the branch, remove the methods in the sample entity (since they're not needed) and merge it. Basically nitpicking 😜

Thanks @JarJak

@lcobucci lcobucci self-assigned this Apr 30, 2017
@lcobucci
Copy link
Member

Merged manually in 38bfcc6. @Ocramius should we backport this to 2.5.x?

@lcobucci lcobucci closed this Apr 30, 2017
@lcobucci lcobucci added this to the 2.6.0 milestone Apr 30, 2017
@Ocramius
Copy link
Member

Ocramius commented May 2, 2017

@lcobucci no, I think this is fine with 2.6.0-only

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

Successfully merging this pull request may close these issues.

None yet

3 participants