You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in your docs I can see that there should be a support for working with associations (OneToOne, OneToMany). But I cannot manage to do some things:
I cannot export foreign keys of the entity - I have tried setQueryBuilder() to use my own QueryBuilder that also gets the association. But it always exports without association. I am using DoctrineReader.
I cannot import data with foreign keys. From docs: For example suppose you have a Product entity that you are importing and must be associated to a Category. If there is a field in the import file named 'Category' with an id, the writer will use metadata to get the association class and create a reference so that it can be associated properly. But there is not any example that would implement this.
If I have a CSV file with Product entity export and it contains Category field, it doesnt work and import fails on violating not null constraint. I have also tried field names: Category.id, Category_id, but it ignores given field. I am using DoctrineWriter.
Could you please provide some examples? Documentation says that the library supports associations.
Thanks
I found out that the problem is that in DoctrineWriter::writeItem(array $item) this method $this->loadAssociationObjectsToObject($item, $object); is called before this one: $this->updateObject($item, $object);.
loadAssociationObjectsToObject sets the associations to a proxy object based on id, but then updateObject(array $item, $object) iterates through all the fields of the object including associations, and sets the associations to integer id. Doctrine then throws error that it was expecting Category object but got integer instead.
So the solution would be to switch order of those methods, or in updateObject only iterate through field names and not associations.
Activity
andrej98 commentedon Aug 16, 2022
I found out that the problem is that in
DoctrineWriter::writeItem(array $item)this method$this->loadAssociationObjectsToObject($item, $object);is called before this one:$this->updateObject($item, $object);.loadAssociationObjectsToObjectsets the associations to a proxy object based on id, but thenupdateObject(array $item, $object)iterates through all the fields of the object including associations, and sets the associations to integer id. Doctrine then throws error that it was expecting Category object but got integer instead.So the solution would be to switch order of those methods, or in
updateObjectonly iterate through field names and not associations.