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

access locale and current locale don't "load" object #759

Open
mpoiriert opened this issue Feb 19, 2024 · 3 comments
Open

access locale and current locale don't "load" object #759

mpoiriert opened this issue Feb 19, 2024 · 3 comments

Comments

@mpoiriert
Copy link

mpoiriert commented Feb 19, 2024

The default and current local of a translation is done via the "postLoad".

When have a proxy object the post load event is only triggered if we access a property that is not in the list of "$skippedProperties"

Accessing any property that are not in the orm (and id) will not trigger the post load event.

so this code:

protected function doTranslate(?string $locale = null, bool $fallbackToDefault = true): TranslationInterface
{
   if ($locale === null) {
     $locale = $this->getCurrentLocale();
    }
       
    // ...
}

Will always return 'en' on the first call if "translate" is the first method call (proxy will not get initialize).

Which is the wrong behavior.

I have not idea how to fix this properly since it's doctrine proxy factory that decide which proper to that should be skipped.

 while ($reflector) {
   foreach ($reflector->getProperties($filter) as $property) {
     $name = $property->name;

     if ($property->isStatic() || (($class->hasField($name) || $class->hasAssociation($name)) && ! isset($identifiers[$name]))) {
       continue;
     }

     $prefix = $property->isPrivate() ? "\0" . $property->class . "\0" : ($property->isProtected() ? "\0*\0" : '');

     $skippedProperties[$prefix . $name] = true;
   }

   $filter    = ReflectionProperty::IS_PRIVATE;
   $reflector = $reflector->getParentClass();
}
@pdias
Copy link

pdias commented Mar 25, 2024

Any solution to this problem?

@pdias
Copy link

pdias commented Mar 26, 2024

I have solved this using fetch EAGER in my entity relation:

#[ORM\ManyToOne(fetch: 'EAGER', targetEntity: Gender::class, inversedBy: 'staffs')]
#[ORM\JoinColumn(name: 'gender', referencedColumnName: 'id')]
private $gender;

@bobvandevijver
Copy link
Contributor

See #767 for a fix.

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

No branches or pull requests

3 participants