Send the data from one table to another

1

And the following, I have an entity called Post where there is a post record and I have an entity called Machine. The objective is:

Haveatableequaltowherewecreatedamachineandthebuttonswhereyouareviewingandeditinginsteadofthoseyouwillhavetoconvert.Whenweloadthere,thelinegoesfromentitytoentity.

ThecodeIalreadyhaveisthefollowing:ThisisentityMaquina.new

And in the MachineController:

Butgivemeerror.

Imadeaprintscrmtothescreensoyoucanbetterseetheerrorthatappearstome.

    
asked by anonymous 05.02.2015 / 18:30

1 answer

1

From what I understand, you're trying to convert an entity of type Posto to an entity of type Maquina , right?

In your createAction method you are instantiating an entity of type Maquina without filling in all its values. And the table exists that some values are non-null, as it accuses the error you posted.

In my opinion, the method should look something like this:

public function createAction($id)
{
    $posto = $this->getDoctrine()->getPostoRepository()->find($id);

    $maquina = new Maquina();
    $maquina->setNumero( $posto->getNumero() );
    $maquina->setDescricao( $posto->getNumero() );
    $maquina->setEndereco( $posto->getNumero() );
    $maquina->setestacao( $posto->getNumero() );
    $maquina->setProtocolo( $posto->getNumero() );
    $maquina->setAtivo( $posto->getNumero() );
    $maquina->setLer( $posto->getNumero() );
    $maquina->setDtype('maquina');

    $this->getDoctrine()->getManager()->persist($maquina);
    $this->getDoctrine()->getManager()->flush();

    return $this->redirect($this->generateUrl('manutencao_maquina', array('id' => $id)));
}
    
06.02.2015 / 11:59