Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

107
Vistas
Pommbundle Custom query Insert or update - Symfony2

I would like to create a custom insert or update with pommbundle but in the documentation i have just for a select query.

It's possible to give me a simple example with a possibility to have a last insert id? with ... currval ou lastval?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There are several ways of inserting data in the database using PommBundle.

If you do not use the Model Manager and you want to perform a custom insertion:

// in the controller
$this->get('pomm')
    ->getDefaultSession()
    ->getQueryManager()
    ->query('INSERT INTO … VALUES ($*::text, $*::int4…)', [$param1, $param2]);

This method is tedious because you have to specify all the fields by hand, it may break if the schema changes but you can specify a complex insertion query using SQL acrobatics.

If the goal is just to save a model, the model manager eases the insertion of data using entities:

use Path\To\Model\MyDb\MySchema\MyEntityModel;

// …
$entity = $this->get('pomm')
    ->getDefaultSession()
    ->getModel(MyEntityModel::class)
    ->createAndSave(['field1' => $param1, …]);

The returned entity is the image of the inserted data with the database default values (most of the time auto generated primary key).

Here is the documentation about it.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda