-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
[2.0] Problem with inversed OneToOne
relationships
#655
Comments
defaults()
method->with()
) in defaults()
method
Hi @simondaigre
nice to hear that! 😊 You problem definitively sounds like a bug. I'm trying to reproduce it. |
hmm I kinda made the same thing, but everything is hydrated as expected 🤔 // Object1Factory
protected function defaults(): array|callable
{
return [
'object2' => Object2Factory::new()->withSomeObject(),
];
}
// Object2Factory
public function withSomeObject(): static
{
return $this->with(static fn (): array => ['object3' => Object3Factory::new(['prop1' => 'toto'])]);
} any chance you create a public reproducer please? |
ok, I confirm that there is a bug: |
->with()
) in defaults()
methodOneToOne
relationships
Any update on this one? I have the same issue. |
hey @mmarton @simondaigre the bug is fied in #659 |
Hi @nikophil, I confirm the issue is fixed with your patch, thanks ! |
Hi! it created me a lot more errors than I originally had :/ I will investigate more and come back with the results with 2.2.2: Tests: 58, Assertions: 215, Errors: 3 |
Which error does it give you? |
Only checked the first issue, but it looks like it broke every 1:1 relations i have: <?php
declare(strict_types=1);
namespace App\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity]
class Event
{
#[ORM\Column(type: Types::INTEGER)]
#[ORM\Id]
#[ORM\GeneratedValue]
private ?int $id = null;
#[ORM\OneToOne(mappedBy: 'event', cascade: ['persist', 'remove'])]
#[Assert\Valid]
private EventLimit $eventLimit;
public function __construct()
{
$this->setEventLimit(new EventLimit());
}
public function getId(): ?int
{
return $this->id;
}
public function getEventLimit(): EventLimit
{
return $this->eventLimit;
}
public function setEventLimit(EventLimit $eventLimit): static
{
// set the owning side of the relation if necessary
if ($eventLimit->getEvent() !== $this) {
$eventLimit->setEvent($this);
}
$this->eventLimit = $eventLimit;
return $this;
}
} <?php
declare(strict_types=1);
namespace App\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class EventLimit
{
#[ORM\Column(type: Types::INTEGER)]
#[ORM\Id]
#[ORM\GeneratedValue]
private ?int $id = null;
#[ORM\OneToOne(inversedBy: 'eventLimit', cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: false)]
private ?Event $event = null;
public function getId(): ?int
{
return $this->id;
}
public function getEvent(): ?Event
{
return $this->event;
}
public function setEvent(Event $event): static
{
$this->event = $event;
return $this;
}
} <?php
declare(strict_types=1);
namespace Tests\Factory;
use App\Entity\Event;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
/**
* @extends PersistentProxyObjectFactory<Event>
*/
final class EventFactory extends PersistentProxyObjectFactory
{
public static function class(): string
{
return Event::class;
}
protected function defaults(): array
{
return [
'eventLimit' => EventLimitFactory::new(),
];
}
} <?php
declare(strict_types=1);
namespace Tests\Event;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Tests\Factory\EventFactory;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;
class EventdTest extends KernelTestCase
{
use Factories;
use ResetDatabase;
public function testIssue(): void
{
$event = EventFactory::createOne();
self::assertTrue(true);
}
}
|
yes thanks for this, I do see where it comes from, and I currently have no solution, have to dig a little bit more |
ok, this problem is really hard to fix... I've found a solution, that MIGHT work, but I'm not so proud of it 😅 Could you test this PR #726 🙏 @simondaigre @mmarton (I've not managed to reproduce your problem with our fixtures, I'm gonna give another try) thanks! |
Hi! Thank you for your work. |
@nikophil Still OK for me 👍 |
I've managed to reproduce your problem in the tests! I think you won't need to create any reproducer app 🤞 |
Hello there,
I'm upgrading a project from 1.38 to 2.0. With the Rector rule, the upgrade is really smooth, thanks @nikophil !
I just have a minor issue, in one Factory, in the
defaults()
method, I'm doing something like this :And in Customer factory :
With Foundry 1.38, my Customer was containing an User, since 2.0 User is always null.
Is it something deprecated or a bug ?
The text was updated successfully, but these errors were encountered: