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

[WIP] Support UUID as a choice value for DocumentType #236

Open
wants to merge 14 commits into
base: 3.x
Choose a base branch
from

Conversation

koemeet
Copy link

@koemeet koemeet commented Nov 22, 2015

I am trying to make the DocumentType support UUIDs too (useful for API's). It is very hacky in my opinion, maybe someone else with more experience could lead me into the right direction.

Related issue #103

@koemeet
Copy link
Author

koemeet commented Nov 22, 2015

I have a better solution now, by using the UUIDHelper class, so based on what kind of value you submit to the form it will check according to that. Only drawback is that I had to copy over the DoctrineChoiceLoader and override the choice_loader option on the DocumentType.

@koemeet
Copy link
Author

koemeet commented Nov 22, 2015

@dbu Could you give feedback if this is usable?

@@ -82,7 +83,7 @@ public function getEntitiesByIds($identifier, array $values)
}));

if (0 == count($values)) {
return array();
return [];
Copy link
Member

Choose a reason for hiding this comment

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

this is only valid with php 5.4+. lets not change that yet, but when we go 2.0 and drop 5.3 support.

…rt 3.0; Also worked through code comments and made necessary changes.

Now extends DoctrineChoiceLoader from the doctrine-bridge. Only changed code is now in there.
…t would still try to use a UUID, but now it will skip it and fall back to using IDs only.
foreach ($values as $val) {
$where->same($val, $alias);
if (UUIDHelper::isUUID($val) && $this->classMetadata) {
Copy link
Member

Choose a reason for hiding this comment

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

i would change the order of the checks. and add another check on classMetadata to see if the document is referenceable.

@koemeet
Copy link
Author

koemeet commented Dec 1, 2015

Ready (I could rebase it to one commit if you would like to)

@dbu
Copy link
Member

dbu commented Dec 9, 2015

yes, please squash the commits into one and then rebase on master (we touched the .travis.yml and composer.json, there will be some conflicts)

@dbu
Copy link
Member

dbu commented Dec 9, 2015

@soullivaneuh are you familiar with the ORM EntityType? would you maybe have time to look at this pull request and see if you have an idea how to need less code to achieve this? the problem is that with the anonymous callback functions, we need to copy a lot of code to achieve small changes...

private $idReader;

/**
* @var null|EntityLoaderInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

EntityLoaderInterface|null

Just a detail, but this will keep code consistency. ;-)

@soullivaneuh
Copy link
Contributor

@dbu well, I have to admin I don't use DoctrinePHPCRBundle actually.

What do you exactly want from me?

If I'm not wrong, Doctrine ORM support UUID mapping: http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#identifier-generation-strategies

Would not this be better to propose this PR directly on Symfony Doctrine bridge, especialy for the choice loader?

@dbu
Copy link
Member

dbu commented Dec 9, 2015

thanks for the feedback @soullivaneuh .
this bundle builds on top of the bridge. the problem is that this PR is copying a lot of code from there in order to add a few things. but with the callbacks, there seems to be no evident way to avoid copying code. so if you would have an idea how to avoid duplication, that would be awesome.

@dbu dbu changed the base branch from master to 2.x July 4, 2022 08:54
@dbu dbu changed the base branch from 2.x to 3.x May 12, 2023 15:05
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.

5 participants