Get created object with all fields

158 views Asked by At

I use DBIx::class and postgreSQL. Imagine table 'Company'. It has fields:

id =>  {
  data_type         =>  'integer',
  is_auto_increment =>  1,
},
name => {
  data_type   =>  'text',
},
is_client => {
  data_type     =>  'boolean',
  default_value =>  'true',
},

When I create new company passing the company name only, create method returns primery key and field I passed: id, name. How can I get all fields with default values without additional request to DB? In other words, I want the create method to return all fields with defaults to me.

1

There are 1 answers

2
Alexander Hartmaier On

The DBIx::Class::ResultSet create method returns a DBIx::Class::Result object which has all column values filled. On databases that support it, DBIx::Class uses RETURNING to get back server populated column values. See https://metacpan.org/pod/DBIx::Class::ResultSource#retrieve_on_insert how to use that feature.