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 identity through foreign entities #6701
Conversation
|
||
try { | ||
$this->_schemaTool->createSchema(array( | ||
$this->_em->getClassMetadata(__NAMESPACE__ . '\GH6531User'), |
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.
You should probably use the ::class
syntax here
$this->_em->getClassMetadata(__NAMESPACE__ . '\GH6531OrderItem'), | ||
$this->_em->getClassMetadata(__NAMESPACE__ . '\GH6531Product'), | ||
)); | ||
} catch (\Exception $e) { |
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.
Catch only tools exceptions, please
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've copy-pasted the try/catch from some older test. Is it actually good for something? It's never used in more recent tests as I can see now. Shouldn't I rather throw it away?
class GH6531Address | ||
{ | ||
/** @Id @OneToOne(targetEntity="GH6531User") */ | ||
private $user; |
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.
Use a public
property instead
private $id; | ||
|
||
/** @Column(type="string") */ | ||
private $title; |
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.
Remove any fields and methods that aren't strictly required for the test scenario
/** @OneToMany(targetEntity="GH6531ArticleAttribute", mappedBy="article", cascade={"ALL"}, indexBy="attribute") */ | ||
private $attributes; | ||
|
||
public function __construct($title) |
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.
If the title is not required, drop this
|
||
/** @Column(type="string") */ | ||
private $value; | ||
|
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.
Same as above: drop any non-strictly-required fields
private $items; | ||
|
||
/** @Column(type="boolean") */ | ||
private $payed = false; |
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.
Same: drop anything that isn't strictly needed
*/ | ||
class GH6531Address | ||
{ | ||
/** @Id @OneToOne(targetEntity="GH6531User") */ |
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.
Use ::class
also when referencing classes in annotations
/** | ||
* @group GH-6531 | ||
*/ | ||
public function testDynamicAttributes(): void |
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.
Drop passing tests fron the testcase
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.
Ah, never mind, not this one 🤔
@vhenzl does this set of tests fail also on 2.5.x? |
Most likely, but if you throw it away you also need a tearDown to handle
dropping tables at the end of a test cycle
On 13 Sep 2017 08:26, "Vašek Henzl" <notifications@github.com> wrote:
*@vhenzl* commented on this pull request.
------------------------------
In tests/Doctrine/Tests/ORM/Functional/Ticket/GH6531Test.php
<#6701 (comment)>:
+ protected function setUp(): void
+ {
+ parent::setup();
+
+ try {
+ $this->_schemaTool->createSchema(array(
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\GH6531User'),
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\GH6531Address'),
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\GH6531Article'),
+ $this->_em->getClassMetadata(__NAMESPACE__ .
'\GH6531ArticleAttribute'),
+ $this->_em->getClassMetadata(__NAMESPACE__ .
'\GH6531Customer'),
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\GH6531Order'),
+ $this->_em->getClassMetadata(__NAMESPACE__ .
'\GH6531OrderItem'),
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\GH6531Product'),
+ ));
+ } catch (\Exception $e) {
I've copy-pasted the try/catch from some older test. Is it actually good
for something? It's never used in more recent tests as I can see now.
Shouldn't I rather throw it away?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#6701 (comment)>,
or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAJakHO09g1xV4yY3G5uAcX_hCPYz1RBks5sh3V3gaJpZM4PVkuP>
.
|
@Ocramius On 2.5 branch fails only first test ( |
@Ocramius, I did some digging in the code and commit history regarding this issue and I have a question: Was this use case actually ever supported? Ie. identity through foreign entities with id strategy set to "AUTO" (ie. to "IDENTITY" or "SEQUENCE")? Current error
appears since b889e18. Before that commit, error message would be
There was a discussion (see here) in PR #1176 if the check throwing this exception should be removed or not. It was removed eventually, but apparently shouldn't be. Anyway, according to this error message, I assume that identity through foreign entities with database generated id never was supported and this PR doesn't make sense then. If this is true, then the documentation is wrong (from the beginning) and needs to be updated to use With Side note on different behaviour for 2.5 and 2.6 when in master branch fail all three tests but on 2.5 only first one. |
@vhenzl since they're part of the documentation I'd assume that the feature worked fine in the past and we broke that due to lack of testing... |
@vhenzl @Ocramius I've rebased the branch to sync with (edit) After thinking a bit more, I believe we should fix this on |
@vhenzl you are indeed correct. We're now discussing internally the procedure to take (if we'll solve this in 2.X or 3.0 only). In the meantime, switch the User to assigned and it should work. PS: And the documentation should also be addressed... =( |
Just adding some use case for this particular issue. Assuming you have an association (can be seen as a Many To Many relation) that need additional information, you're defining a new Entity. For example, here is a relational entity that has a "name": /**
* @ORM\Entity
*/
class RelatedToDummyFriend
{
/**
* @ORM\Column
*/
public $name;
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="DummyFriend")
* @ORM\JoinColumn(name="dummyfriend_id", referencedColumnName="id", nullable=false)
*/
public $dummyFriend;
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="RelatedDummy", inversedBy="relatedToDummyFriend")
* @ORM\JoinColumn(name="relateddummy_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
public $relatedDummy;
} This is a common use case to me. Using This used to work pre
Note that this is how it's persisted:
Both |
@soyuka why not using what the lib offers for |
Because you can (could?) not add custom columns to the ManyToMany entity (the association table). I think that I discussed that with @Ocramius somewhere but can't find the issue anymore. Anyway the conclusion was that if you need to add fields to a ManyToMany relation, you need to create a new entity. Obviously, in the case above you could easily add a column with an |
@soyuka I do agree that if (and when) needed you can have an entity to connect stuff but let's be clear that these are not |
indeed those are not many-to-many, as said above can be seen as It does work if my the two associations have been |
Yeap, because then you do have identifiers for your relations 😉 |
What do you mean by "reference identifier"? I like having associations as identifier. Anyway, this works just fine as long as you save the relation before saving the relation entity. |
Tests are based on examples from "Composite and Foreign Keys as Primary Key" tutorial: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html
@Ocramius I've moved the fix from #7003 (with some minor fixes) to this PR and things are working fine. We did have some impact on insertion performance ( - benchHydration I0 P0 [μ Mo]/r: 480,363.000 480,363.000 (μs) [μSD μRSD]/r: 0.000μs 0.00%
+ benchHydration I0 P0 [μ Mo]/r: 482,352.000 482,352.000 (μs) [μSD μRSD]/r: 0.000μs 0.00% Could you please check if this is acceptable or if we can optimise things a bit more? |
@lcobucci that impact is OK 👍 |
This prevents a throw in UnitOfWork#addToIdentityMap because some fields are null.
@Ocramius alright then, I'll merge this in and make it part of |
@Ocramius I'm still working on porting this to |
Fix ID generation of foreign keys Ports #6701 using v3.0 structure.
@lcobucci @Ocramius I'm currently having this issue in doctrine 2.5 ... But even after manually applying this PR's patch I still have the issue. So I wanted to know 1) if this was, according to you, a 2.6 issue only, or 2) it's an issue in 2.5 too and fixing it requires more than the current patch ? |
@tonivdv since the release of v2.6.0 we no longer maintain v2.5.x and recommend every one to migrate to the newer version. We just backport security fixes to v2.5.x, which didn't happen so far 👍 |
@lcobucci Yeah I know and trust me I'm crying (:p) here but one of the projects can't be migrated to 2.6 because it can't be migrated easily at this stage to php 7 . Anyway, I changed the entity to prevent this issue, so as soon as we migrate the php 7 we'll update doctrine accordingly. But according to you the issue is still present in 2.5 right? Thanks for the quick response. Cheers |
It's highly possible that it still there. |
Failing tests for #6531 (and also #6043).
Tests are based on examples from Composite and Foreign Keys as Primary Key tutorial. None of all three examples of Identity through foreign Entities works at the moment. All of them fail with a similar error: