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

Fix toOne translation fields #30

Merged

Conversation

jordisala1991
Copy link
Contributor

Fixing the problem of #10

Also closes: #25 #13

@jordisala1991
Copy link
Contributor Author

@tchapi or @webda2l could you approve the workflow, so we can see what needs to be fixing on the test side?

@webda2l
Copy link
Member

webda2l commented Feb 17, 2022

It's not that so simple as explained elsewhere #25 (comment) & #13 (comment)

@jordisala1991
Copy link
Contributor Author

jordisala1991 commented Feb 17, 2022

I just applied this to my project and it works like a charm, mind yo explain why it does not work?

(Im trying with ManyToOne, maybe the problem if it is ManyToMany?)

@jordisala1991 jordisala1991 force-pushed the hotfix/fix-to-many-translation-fields branch from cea93cf to 2d0dedd Compare February 17, 2022 15:16
@jordisala1991
Copy link
Contributor Author

Let's start again, by adding a failing test... I'm trying to fix it but I always end up in a infinite loop

@jordisala1991 jordisala1991 force-pushed the hotfix/fix-to-many-translation-fields branch from 2d0dedd to 8700fb6 Compare February 17, 2022 16:06
@jordisala1991
Copy link
Contributor Author

Can you take a look at the proposed solution? @webda2l

$assocsConfigs[$assocName] = [
'field_type' => AutoFormType::class,
'data_class' => $class,
'required' => !$nullable,
'required' => false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I don't change this, association fields are always created empty. Shouldn't this be just required false directly?

if (!$metadata->isAssociationInverseSide($assocName)) {
$associationMapping = $metadata->getAssociationMapping($assocName);

if (isset($associationMapping['inversedBy'])) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the real fix, the other change is to avoid creating empty objects.

continue;
}

$class = $metadata->getAssociationTargetClass($assocName);

if ($metadata->isSingleValuedAssociation($assocName)) {
$nullable = ($metadata instanceof ClassMetadataInfo) && isset($metadata->discriminatorColumn['nullable']) && $metadata->discriminatorColumn['nullable'];
Copy link
Contributor Author

@jordisala1991 jordisala1991 Feb 17, 2022

Choose a reason for hiding this comment

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

I didn't understood this line, discriminatorColumn is for inheritance, not sure what is the relation with the nullable thing.

@jordisala1991 jordisala1991 force-pushed the hotfix/fix-to-many-translation-fields branch from aa16114 to 65222a8 Compare February 17, 2022 16:29
@webda2l
Copy link
Member

webda2l commented Feb 17, 2022

Thanks @jordisala1991, I will check later this weekend with #10 (comment) to try to refresh my memory about this, but it's sound good :)

@webda2l webda2l merged commit 217da01 into a2lix:master Feb 19, 2022
@jordisala1991 jordisala1991 deleted the hotfix/fix-to-many-translation-fields branch February 19, 2022 16:16
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.

3 participants