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

Expr::references should go through discriminator map #1333

Merged
merged 4 commits into from
Jan 7, 2016

Conversation

malarzm
Copy link
Member

@malarzm malarzm commented Jan 7, 2016

Before it was throwing an exception that field was not found. Test case is written like this only for the sake of testing, normally we use same type of references everywhere, only fields are named differently in child classes for the sake of making sense :)

@malarzm malarzm added the Feature label Jan 7, 2016
@malarzm malarzm added this to the 1.1 milestone Jan 7, 2016
}
}
if ( ! isset($mapping) || $mapping === null) {
throw $e;
Copy link
Member

Choose a reason for hiding this comment

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

This would throw an exception with the message "No mapping found for field '$fieldName' in class '$className'." - should we change that to mention that we've tried child classes as well to let people know about that?

Copy link
Member Author

Choose a reason for hiding this comment

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

"No mapping found for field '$fieldName' in class '$className' nor its descendants." ?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good!

Copy link
Member Author

Choose a reason for hiding this comment

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

Oook, now I'll need to add more tests :P

@alcaeus
Copy link
Member

alcaeus commented Jan 7, 2016

Looks good! 👍

@malarzm
Copy link
Member Author

malarzm commented Jan 7, 2016

Exception added and rebased atop new master for quick merge :)

$childClass = $this->dm->getClassMetadata($child);
if ($childClass->hasAssociation($this->currentField)) {
$mapping = $childClass->getFieldMapping($this->currentField);
break;
Copy link
Member

Choose a reason for hiding this comment

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

Rather than give up after finding the first mapping, I think we should check all discriminator possibilities and throw if we find two conflicting mappings. It should be sufficient to compare the mapping arrays with ===.

This would warn users about an edge case of two child classes defining conflicting mappings and remove the ambiguity of selecting the first one that happened to show up during our discriminator map scan.

@malarzm
Copy link
Member Author

malarzm commented Jan 7, 2016

I just recalled that includesReferenceTo is a thing, will update that method as well

@alcaeus
Copy link
Member

alcaeus commented Jan 7, 2016

👍 on the changes to catch conflicting field mappings as well!

@jmikola
Copy link
Member

jmikola commented Jan 7, 2016

LGTM!

malarzm added a commit that referenced this pull request Jan 7, 2016
Expr::references should go through discriminator map
@malarzm malarzm merged commit 7a8325b into doctrine:master Jan 7, 2016
@malarzm malarzm deleted the qb-references branch January 7, 2016 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants