Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!