Skip to content

Working with association #132

Open
Open

Description

@andrej98

Hello,

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:

  1. 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.

  2. 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

Activity

  1. andrej98 commented on Aug 16, 2022

    @andrej98
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions