data-import icon indicating copy to clipboard operation
data-import copied to clipboard

DoctrineWriter relational value automatically converting to string

Open muratbeser opened this issue 10 years ago • 5 comments

Hi, My English isn't perfect firstly I'm sorry for that.

I have two entity WISPUserAccount and BirdRecord, they are mapped as OneToMany UserAccount has to have a BirdRecord...

Sometimes Writer trying to convert it to a string...

My Bird Record Class

class BirdRecord { 
public function __toString() { (string) $this->name; }
}

Data Import Code

$bird = $this->getBird(); // returns BirdRecord object
$userNameFixConverter = new CallbackItemConverter(function ($item) use ($bird) {
            $item["bird"] = $bird;
});
$workflow->addItemConverter($userNameFixConverter);
$workflow->setSkipItemOnFailure(true);
$result = $workflow->process();

Error Message:

A new entity was found through the relationship 'Black\Bundle\CustomerBundle\Entity\WISPUserAccount#bird' that was not configured to cascade persist operations for entity: BS-WB-DEV. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"})

muratbeser avatar Jan 10 '15 15:01 muratbeser

I don't know what do you want to archive, but the error message comes from doctrine. It says that you need to add persist to your cascade option.

Here are the link to the docs: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#transitive-persistence-cascade-operations

Baachi avatar Jan 13 '15 15:01 Baachi

I know that the problem I can't bind an object from there if my entity has __toString() method

muratbeser avatar Jan 15 '15 22:01 muratbeser

@Baachi : actually, I don't think cascade is use for TRUNCATE. The second argument of getTruncateTableSQL should be set to true in the doctrine writer.

greg0ire avatar Mar 18 '15 17:03 greg0ire

@Baachi : I was looking for a truncate cascade bug, but this has nothing with this issue sorry. Making a P.R. nonetheless.

greg0ire avatar Mar 18 '15 17:03 greg0ire

@greg0ire No problem, but thank you for your help.

@muratbeser can you create a repo which describe the bug? Maybe it can help to spot the problem.

Baachi avatar Mar 19 '15 07:03 Baachi