I have two entities: Product
and Image
and many Products can have many
Images so this generates a third table ProductHasImages
. Entities are right
as doctrine:schema:validate
command outputs:
Symfony > doctrine:schema:validate
[Mapping] OK - The mapping files are correct.
[Database] FAIL - The database schema is not in sync with the current
mapping file.
The command terminated with an error status (2)
I've added this lines to my config.yml
:
services:
tan.common.admin.image:
class: Tan\CommonBundle\Admin\ImageAdmin
tags:
- { name: sonata.admin, manager_type: orm, label: "Imagenes",
show_in_dashboard: false }
arguments: [null, Tan\CommonBundle\Entity\Image, null]
I've have the file Tan\CommonBundle\Admin\ImageAdmin.php
created with the
following content:
<?php
namespace Tan\CommonBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
class ImageAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('file', 'file', array('required' => false));
}
public function prePersist($image)
{
$this->manageFileUpload($image);
}
public function preUpdate($image)
{
$this->manageFileUpload($image);
}
private function manageFileUpload($image)
{
if ($image->getFile()) {
$image->refreshUpdated();
}
}
}
Now I'm trying to add the image
field to ProductAdmin.php
as follow:
protected function configureFormFields(FormMapper $form)
{
$form
->add('product_name', null, array('label' => 'Nombre'))
->add('product_description', null, array('label' => 'Descripción'))
->add('image', 'sonata_type_admin', array('delete' => false));
}
But any time I try to add a new product I get this error:
The current field
image
is not linked to an admin. Please create one for the target entity : ``
Why? What I'm doing wrong?