Reputation:
It is throwing an error
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'complete' cannot be null
How do I "tell" the Entity Manager not to consider the fruit object since it is throwing an error?
I have an object like:
class Fruit {
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/** @Column(type="string", length=10, nullable=true) */
private $name;
/** @Column(type="boolean") */
private $complete;
/* Omitted to make it simple */
}
And a method like:
public function uploadAction(){
try{
/* Omitted to make it simple */
while ($data = fgetcsv($fic, 1024, $delimiter)) {
try {
$fruit = $fruitManager->createFruit($data);
$outcome_fruit = $fruit->id;
} catch (\Exception $e) {
$outcome_details[] = $e->getMessage();
}
}
fclose($fic);
@unlink($file_path);
$csv_data = $this->view->io->build_csv_file($outcome_details);
$csv_import->output_csv = base64_encode(gzencode($csv_data));
$this->em->persist($csv_import);
// error here
$this->em->flush();
//
} catch (\Exception $e) {
print $e->getMessage();
exit;
}
}
My fruitManager
class FruitManager{
public function createFruit($name){
$fruit = new \Entities\Fruit;
$fruit->name = $name;
throw new Exception("Exception.");
$fruit->complete = 1;
$this->em->persist($fruit);
$this->em->flush();
}
}
Upvotes: 0
Views: 1139
Reputation: 484
You have few options:
/** @Column(type="boolean", nullable=true) */
/** @ORM\Column(type="boolean", nullable=false, options={"default" : false}) */
private $complete = false;
like Freelancer saidI'd prefer one of the first 2 options depending on logic needs. Thanks.
Upvotes: 2