-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Restore bc for annotations #8758
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
|
||
use Attribute; | ||
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; | ||
use Doctrine\Deprecations\Deprecation; | ||
|
||
/** | ||
* @Annotation | ||
|
@@ -57,6 +58,14 @@ public function __construct( | |
string $fetch = 'LAZY', | ||
?string $inversedBy = null | ||
) { | ||
if ($targetEntity === null) { | ||
Deprecation::trigger( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @greg0ire I realize I'm a little late to the party on this one, but I just noticed the deprecation in our dev logs today. One of the features of 2.9 was automatic type detection when using typed properties, but these deprecations imply that with ORM 3.0 that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know how type detection works, but it looks kind of strange to me that the build passed prior to this, with a required constructor argument. Maybe type detection is done before building this class? If not, then something is off. Can you please find the PR which introduced automatic type detection? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #8439 was the base PR and there are a couple follow-ons after it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could be wrong, but from this PR you linked, it looks like the detection happens in order to complete the mapping and make it valid (provide that I'll stop the investigation here, if you still think it negates the automatic type detection feature, please send a failing test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The But, this PR also adds deprecations when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm under the impression that you think that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I'm clearly not communicating my concern very well. I have these two simplified entities in my app: <?php declare(strict_types=1);
namespace App\Entity;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EntityRepository::class)]
#[ORM\Table]
class UserDocument
{
#[ORM\Column(nullable: false)]
#[ORM\Id]
#[ORM\GeneratedValue]
private ?int $id = null;
#[ORM\ManyToOne(cascade: ['persist', 'remove'], inversedBy: 'documents')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
public User $user;
public function __construct(User $user)
{
$this->user = $user;
}
public function getId(): ?int
{
return $this->id;
}
} <?php declare(strict_types=1);
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EntityRepository::class)]
#[ORM\Table]
class User
{
#[ORM\Column(nullable: false)]
#[ORM\Id]
#[ORM\GeneratedValue]
private ?int $id = null;
/**
* @var Collection<UserDocument>
*/
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserDocument::class, cascade: ['persist'], fetch: 'EXTRA_LAZY')]
private Collection $documents;
public function __construct()
{
$this->documents = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function addDocument(UserDocument $document): void
{
$this->documents->add($document);
}
public function removeDocument(UserDocument $document): void
{
$this->documents->removeElement($document);
}
/**
* @return Collection<UserDocument>
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function hasDocument(UserDocument $document): bool
{
return $this->documents->contains($document);
}
public function getDocumentCount(): int
{
return $this->documents->count();
}
} This triggers the "Passing no target entity is deprecated. (ManyToOne.php:65 called by UserDocument.php:17, #8753, package doctrine/orm)" deprecation message. The mapping works fine now because of the automatic type detection feature (ultimately Do I need to restore the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes it makes more sense to me now, and I see that logically, a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Working on it at #8784 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks for being patient, I'm unfamiliar with the auto-detection feature and the fact that it's only implemented for some of the relationships did not help with understanding 😅 |
||
'doctrine/orm', | ||
'https://github.com/doctrine/orm/issues/8753', | ||
'Passing no target entity is deprecated.' | ||
); | ||
} | ||
|
||
$this->targetEntity = $targetEntity; | ||
$this->cascade = $cascade; | ||
$this->fetch = $fetch; | ||
|
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 adding nullable when it gets deprecated?
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.
See the commit message :)