Skip to content

Instantly share code, notes, and snippets.

@rbo
Created March 10, 2011 07:33
Show Gist options
  • Save rbo/863707 to your computer and use it in GitHub Desktop.
Save rbo/863707 to your computer and use it in GitHub Desktop.
Part of DBIx::Class::Storage::DBI->insert()
# list of primary keys we try to fetch from the database
# both not-exsists and scalarrefs are considered
my %fetch_pks;
for ($source->primary_columns) {
$fetch_pks{$_} = scalar keys %fetch_pks # so we can preserve order for prettyness
if ! exists $to_insert->{$_} or ref $to_insert->{$_} eq 'SCALAR';
}
my ($sqla_opts, @ir_container);
if ($self->_use_insert_returning) {
# retain order as declared in the resultsource
for (sort { $fetch_pks{$a} <=> $fetch_pks{$b} } keys %fetch_pks ) {
push @{$sqla_opts->{returning}}, $_;
$sqla_opts->{returning_container} = \@ir_container
if $self->_use_insert_returning_bound;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment