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

set metadata for interface to be able to fetch entites by interface name #385

Closed

Conversation

Burgov
Copy link
Contributor

@Burgov Burgov commented Jun 29, 2012

using the new ResolveTargetEntity functionality we noticed we needed another feature:

From the Symfony Bundle defining the interface, we'd like to be able to fetch entities by this very interface name, e.g.:

$em->find('Foo\BarBundle\Entity\PersonInterface', 1);

or

$em->getRepository('Foo\BarBundle\Entity\PersonInterface')->findAll();

This PR sets metadata for the interface when metadata for a class is loaded that the interface is configured for

@travisbot
Copy link

This pull request fails (merged 466d87f7 into cc29f85).

@@ -66,6 +66,12 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $args)
$this->remapAssociation($cm, $mapping);
}
}

foreach($this->resolveTargetEntities as $interface => $data) {
Copy link
Member

Choose a reason for hiding this comment

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

missing space after foreach

@travisbot
Copy link

This pull request fails (merged c9386785 into cc29f85).

@Burgov
Copy link
Contributor Author

Burgov commented Jun 29, 2012

Hm, this only works if the CM for the actual entity is loaded before requesting the CM for the interface (see added failing test)... Any suggestions?

@travisbot
Copy link

This pull request fails (merged 8fca5591 into cc29f85).

@beberlei
Copy link
Member

beberlei commented Jul 4, 2012

hm this would be very cool, but i dont see a way to get it working.

@Burgov
Copy link
Contributor Author

Burgov commented Jul 4, 2012

@beberlei perhaps a new preLoadClassMetadata event can be introduced. The ResolveTargetEntityListener could then listen into this event and make sure the original class is loaded, which in turn (if this PR would be merged) would make sure the interface metadata is registered as well

@Burgov
Copy link
Contributor Author

Burgov commented Jul 4, 2012

@beberlei I've added a commit which makes it possble. Let me know what you think.

@beberlei
Copy link
Member

beberlei commented Jul 7, 2012

Yes its better, but i fear you have to start over, we merged a huge refactoring in ClassMetadataFactory.

But my idea would be to throw an event when a classmetadata could not be found, and then allow to recover from that event.

$eventArgs = new \Doctrine\ORM\Event\PreLoadClassMetadataEventArgs($className, $this->em);
$this->evm->dispatchEvent(Events::preLoadClassMetadata, $eventArgs);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

@beberlei this place is now in Common. If you want to trigger an event in this place, you will need to add a hook in Common.

Copy link
Member

Choose a reason for hiding this comment

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

yes i know, thats what i mean with "start over" :-(

but the event should rather be "onClassMetadataNotFound" or something.

@beberlei
Copy link
Member

beberlei commented Jul 7, 2012

i am asking myself if the resolve metadata listener features should be in the core of metadata factory. Adding this event would only be for this use-case. I dont see any other use-case for the event.

@Burgov
Copy link
Contributor Author

Burgov commented Jul 15, 2012

@beberlei What's your pov on this? Should it be in the core? Hopefully I will have time next week to rewrite the commit (or otherwise apply it to common).

@Burgov
Copy link
Contributor Author

Burgov commented Nov 23, 2012

@beberlei I've rebased the branch on to master (and renamed the event as you suggested), but everything still works fine... Can you tell me what needs to change because of the refactoring?

* @param \Doctrine\ORM\Mapping\ClassMetadataInfo $classMetadata
* @param \Doctrine\ORM\EntityManager $em
*/
public function __construct($className, EntityManager $em)
Copy link
Member

Choose a reason for hiding this comment

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

you should tipehint the first argument if it is really a ClassMetadataInfo

@stof
Copy link
Member

stof commented Nov 23, 2012

@Burgov it looks like you messed the ClassMetadataFactory when rebasing, or you forgot to update your master before rebasing. Because currently, it is not based on the current code

@Burgov
Copy link
Contributor Author

Burgov commented Nov 23, 2012

@stof you're right... It helps to rebase onto upstream/master instead of origin/master ^_^

I'll rewrite this PR later on

Events::loadClassMetadata,
Events::onClassMetadataNotFound
);
}
/**
Copy link
Member

Choose a reason for hiding this comment

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

missing empty line

@stof
Copy link
Member

stof commented Nov 23, 2012

you should add some tests

@Burgov
Copy link
Contributor Author

Burgov commented Dec 20, 2012

Any help on this one please? In the original PR an event was dispatched at a place which has now been refactored to a base class in Doctrine/Common, which doesn't have the event dispatcher. I'm not sure how to resolve this...

  • Do I need to make changes in Doctrine/Common or should this remain in Doctrine/ORM?
  • In case of the former - how can I allow for my listener to hook into this?
  • In case of the latter - how could I implement this in the new Doctrine/ORM classmetadatafactory class?

@dgzara
Copy link

dgzara commented Jan 21, 2013

Finally, Could you resolve this? Thanks.

@Ocramius
Copy link
Member

I ported this PR to #1181. Closing here.

@Ocramius Ocramius closed this Nov 11, 2014
@Ocramius Ocramius reopened this Nov 11, 2014
@Ocramius Ocramius closed this Nov 11, 2014
Ocramius added a commit to Ocramius/doctrine2 that referenced this pull request Jan 13, 2015
…licate imports (caused by rebase conflicts)
Ocramius added a commit to Ocramius/doctrine2 that referenced this pull request Jan 13, 2015
Ocramius added a commit to Ocramius/doctrine2 that referenced this pull request Jan 13, 2015
Ocramius added a commit to Ocramius/doctrine2 that referenced this pull request Jan 13, 2015
Ocramius added a commit to Ocramius/doctrine2 that referenced this pull request Jan 13, 2015
…nterface-first fetching of metadata (via fallback logic)
Ocramius added a commit to Ocramius/doctrine2 that referenced this pull request Jan 13, 2015
Ocramius added a commit to Ocramius/doctrine2 that referenced this pull request Jan 13, 2015
Ocramius added a commit to Ocramius/doctrine2 that referenced this pull request Jan 13, 2015
…undEventArgs` from `ManagerEventArgs` instead of generic `EventArgs`
Ocramius added a commit to Ocramius/doctrine2 that referenced this pull request Jan 13, 2015
Ocramius added a commit to Ocramius/doctrine2 that referenced this pull request Jan 13, 2015
…on to new `OnClassMetadataNotFoundEventArgs` API
Ocramius added a commit to Ocramius/doctrine2 that referenced this pull request Jan 13, 2015
Ocramius added a commit to Ocramius/doctrine2 that referenced this pull request Jan 13, 2015
Ocramius added a commit to Ocramius/doctrine2 that referenced this pull request Jan 13, 2015
deeky666 added a commit that referenced this pull request Jan 14, 2015
…entities-by-aliased-name

Support fetching entities by aliased name
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.

6 participants