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
updated addIdentifiersToQuery to work with custom types. #938
updated addIdentifiersToQuery to work with custom types. #938
Conversation
Can you please add some tests @oleg-andreyev ? |
@core23 planning to find some time on weekends. |
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Can you please add a test |
@core23 I’ve got message for stale bot and planning to do it on weekdays. Thanks! |
b478c30
to
cc77f69
Compare
Could you please rebase your PR and fix merge conflicts? |
Hi @oleg-andreyev ! Do you have time to finish this PR ? This seems like almost done ! :) |
d2d6792
to
116056c
Compare
Failing tests aren't related to current PR, can someone please trigger travis manually? |
@oleg-andreyev Done |
@core23 please review PR |
Could you please rebase your PR and fix merge conflicts? |
What is the status of this Pr? |
Are you still interested by this PR @oleg-andreyev ? |
I'll rebase this branch, but it's taking too long to merge, so I completely forgot about this PR. |
There is few contirbutors, but lot of work/issues/PR. |
63c36cd
to
6553c7d
Compare
@@ -982,22 +982,21 @@ public function testGetUrlsafeIdentifierNull(): void | |||
*/ | |||
public function testAddIdentifiersToQuery(array $expectedParameters, array $identifierFieldNames, array $ids): void | |||
{ | |||
$modelManager = $this->getMockBuilder(ModelManager::class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mocking target is a bad practice.
@OskarStark @core23 @phansys I've rebased branch on latest 3.x, please review. |
|
||
$prefix = uniqid(); | ||
$prefix = $this->generateIdentifierPrefix(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why introducing this method ? (Especially when we're trying to avoid protected method).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to have an ability to override it in tests, otherwise, it's impossible to predict results with hardcoded unique
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't add method for this.
You could check the name by using a regex instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One good practice from DDD - avoid having dependencies on I/O outside of the Infrastructure layer, so I tend to remove such dependencies into a separate method/class so that it could be replaced later without affecting main functionality and tests. What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea 💡
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oleg-andreyev In Sonata 4.0, the ModelManager will be final.
- So a protected method is useless, it's basically a private one.
- And creating a private method for calling
uniqid()
seems useless to me.
src/Model/ModelManager.php
Outdated
return Type::getType($fieldType); | ||
} | ||
|
||
private function buildInnerIdentifier(string $prefix, string $field, $value, int $pos, QueryBuilder $qb, ClassMetadata $classMetadata): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot of parameters in this private method.
Is there a way to reduce the number ?
Maybe the parameterName can be an argument instead of passing the prefix and the pos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially wanted to make addIdentifiersToQuery
a bit cleaner and remove chunk of code from foreach-loop but other hand I can revert this private method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method addIdentifiersToQuery
is complex, so this private method has a lot of sens.
$parameterName = sprintf('field_%s_%s_%d', $prefix, $name, $pos);
$this-> buildInnerIdentifier($field, $value, $paraterName, $qb, $classMetadata)
Was just a suggestion, not a blocking point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will reduce a few args. Good idea. Will do it.
if ($this->hasFieldCustomType($fieldType)) { | ||
$type = $this->getFieldCustomType($fieldType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I look at the logic inside these function, I'm not sure we need to add private method for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used in two places. I usually try to remove duplicates. This reduces the burden on the developers when they need to update "Type" class usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I saw the duplicate.
But it's basically like a method
private function foo($a) {
return $this->bar($a);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Similar to findBy and findOneBy
SonataDoctrineORMAdminBundle/src/Model/ModelManager.php
Lines 285 to 293 in 560e9f0
public function findBy($class, array $criteria = []) | |
{ | |
return $this->getEntityManager($class)->getRepository($class)->findBy($criteria); | |
} | |
public function findOneBy($class, array $criteria = []) | |
{ | |
return $this->getEntityManager($class)->getRepository($class)->findOneBy($criteria); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But these one are public, and required by the interface.
- updated addIdentifiersToQuery to work with custom types. - added test for addIdentifiersToQuery: testAddIdentifiersToQueryWithCustomIdMapping - extracted Type operations into getFieldCustomType, extracted loop-part from addIdentifiersToQuery to buildInnerIdentifier
560e9f0
to
16efac2
Compare
@core23 @OskarStark @phansys can you please take a look? |
|
||
$prefix = uniqid(); | ||
$prefix = $this->generateIdentifierPrefix(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oleg-andreyev In Sonata 4.0, the ModelManager will be final.
- So a protected method is useless, it's basically a private one.
- And creating a private method for calling
uniqid()
seems useless to me.
This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Subject
Batch actions do not work with custom types.
I am targeting this branch, because bug.
Changelog