-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
ObjectManagerPersister bad arguments #202
Comments
Hello I've the same issue since i've updated I my case, it's appear because into my fixtures i'm using array:
To testing and try to understand where is the problem, i've added this condition into the ObjectManagerPersister before the testing line with null, and all is fine now (i known it's a bad idea to do this) :
There is another possibility to replace an array by a collection into fixtures (because collection is managed)? Or it's necessary to update the library? Thanks for your help. |
Would it be possible to have access to a reproducer or a more complete sample of the issue? i.e. the fixture, the model behind and the complete stack trace? Because with the current information I have no idea what is causing the issue neither where is it coming from |
Thanks @theofidry for your reply. Entities
Group.php
Fixtures
Group.yaml
And when i launch the command to generate fixtures :
I hope this sample can help you to reproduce this bug and you could be able to fix it. Thanks you |
From the code perspective, this does not look correct to me. A small nitpick: /**
* @var ArrayCollection<int, Group>
*
* @ORM\ManyToMany(targetEntity="App\Entity\Group", inversedBy="users")
*/
public $groups; Should probably be: /**
* @var Collection<int, Group>
*
* @ORM\ManyToMany(targetEntity="App\Entity\Group", inversedBy="users")
*/
public $groups; As that it is an But more to your problem, you have If you want to do something like this, i think it would be more appropriate to make the property private and expose a setter which does |
Hi @theofidry Thanks for your help. I can confirm by changing ArrayCollection to Collection, set my properties to private and adding getter and setter now all is fine.
Last question (after that you can close this issue, of course if it's ok for @TuxxyDOS)
Yes you're right, i'm using strict types.
Thanks you |
Note that I'm aware unless you are using a custom provider. That said I don't recommend trying to pass an |
I think I have a different context than fkizewski. However there's probably a type related solution. Domain\Model\ZmrList /**
* @var iterable|array|Collection
*/
private iterable $listColumns; ORM\Maping\ZmrList.orm.yml Domain\Model\ZmrList:
type: entity
oneToMany:
listColumns:
targetEntity: ListColumn
mappedBy: zmrList fixtures\zmrLists.yaml Domain\Model\ZmrList:
zmrList1:
name: 'BehatTestList1'
label: 'Behat Test List 1'
type: 'Entity'
form: '@form1'
description: 'A list for automated testing' I have these informations... : Doctrine\Persistence\Reflection\TypedNoDefaultReflectionProperty {#132
+name: "listColumns"
+class: "Domain\Model\ZmrList"
modifiers: "private"
extra: {
docComment: """
/**\n
* @var iterable|array|Collection\n
*/
"""
}
}
[]
"listColumns" ... by doing this in ObjectManagerPersister : if ($fieldValueOrFieldValues instanceof Collection) {
foreach ($fieldValueOrFieldValues->getValues() as $fieldValue) {
$this->getMetadata($targetEntityClassName, $fieldValue);
}
} elseif (is_array($fieldValueOrFieldValues)) {
dump($metadata->getReflectionProperty('listColumns'));
dump($metadata->getReflectionProperty('listColumns')->getValue($object));
dd($fieldName);
} Do you have an idea on that @theofidry ? Thanks you very much for your help |
I think it’s the exact same error: a collection (for relationships) in
Doctrine _must_ be Collection instances AFAIK so having an array/iterable
there is wrong in that regard
…On Mon 17 Jan 2022 at 15:49, Helo ***@***.***> wrote:
I think I have a different context than fkizewski. However there's
probably a type related solution.
Domain\Model\ZmrList
/** * @var iterable|array|Collection */
private iterable $listColumns;
ORM\Maping\ZmrList.orm.yml
Domain\Model\ZmrList:
type: entity
oneToMany:
listColumns:
targetEntity: ListColumn
mappedBy: zmrList
fixtures\zmrLists.yaml
Domain\Model\ZmrList:
zmrList1:
name: 'BehatTestList1'
label: 'Behat Test List 1'
type: 'Entity'
form: ***@***.***'
description: 'A list for automated testing'
I have these informations... :
Doctrine\Persistence\Reflection\TypedNoDefaultReflectionProperty {#132
+name: "listColumns"
+class: "Domain\Model\ZmrList"
modifiers: "private"
extra: {
docComment: """ /**\n * @var iterable|array|Collection\n */ """
}
}
[]"listColumns"
... by doing this in ObjectManagerPersister :
if ($fieldValueOrFieldValues instanceof Collection) {
foreach ($fieldValueOrFieldValues->getValues() as $fieldValue) {
$this->getMetadata($targetEntityClassName, $fieldValue);
}
} elseif (is_array($fieldValueOrFieldValues)) {
dump($metadata->getReflectionProperty('listColumns'));
dump($metadata->getReflectionProperty('listColumns')->getValue($object));
dd($fieldName);
}
Do you have an idea on that @theofidry <https://github.com/theofidry> ?
Thanks you very much for your help
—
Reply to this email directly, view it on GitHub
<#202 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABHPVANJUVZCHYJ5MP3YEM3UWQUAFANCNFSM5LFUAZSQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
The only comment i've with your remarks, that's before your last update of the library all is fine with this syntax, i think because we have now a strict types component enabled by default. Thanks for your time. |
I have the same issue. It worked just fine before this update. Please consider reverting the change as I think this is a breaking change. |
I think this may have been introduced by #198. If it is a problem I'll happily accept a PR reverting this behaviour without reverting the bug fix included in the PR.
For what it's worth: this is purely on Doctrine side (to not warn about the incorrect |
Hi @theofidry, I am facing the same issue. I have added a dump to see which entity is causing problems.
Dump result:
So it looks some issue with the Order/Collection method relationship. Here are the entities configurations and fixtures: Order Entity:
Order Fixture:
Collection Method Fixture:
If I edit the checkAssociationsMetadata method by adding this seems all to be working as expected:
composer.json
Can you please tell me if I am doing something wrong ? BTW: I have temporarily fixed using the change suggested by overloading the original class with my class via composer.
|
An attempt to fix it in #207. Please try it |
Hi @theofidry, I have tested and I can confirm #207 is solving the issue for me. Thx @titiyoyo |
Closed via #207. |
Hello
Following this issue : theofidry/AliceBundle#6
I just updated
theofidry/alice-data-fixtures
to 1.5.1 and got this error by launching fixtures :I updated
hautelook/alice-bundle
to 2.10 as well.Thanks you
The text was updated successfully, but these errors were encountered: