- my $object;
-# warn 'cond: ' . Dumper( $self->{cond} ); use Data::Dumper;
-# warn 'where: ' . Dumper( $self->{attrs}{where} ); use Data::Dumper;
- my @missing = grep { !exists $updates->{$_} && !exists $fixed_fields->{$_} } $self->result_source->primary_columns;
- if( defined $self->{cond} && $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION == $self->{cond} ){
- $self->{cond} = undef;
- $self->{attrs}{where} = undef;
- if( ! scalar @missing ){
- $object = $self->find( $updates, { key => 'primary' } );
+ if( $fixed_fields ){
+ carp if !( ref( $fixed_fields ) eq 'HASH' );
+ $updates = { %$updates, %$fixed_fields };
+ }
+ # direct column accessors
+ my %columns;
+
+ # relations that that should be done before the row is inserted into the database
+ # like belongs_to
+ my %pre_updates;
+
+ # relations that that should be done after the row is inserted into the database
+ # like has_many and might_have
+ my %post_updates;
+ for my $name ( keys %$updates ){
+ my $source = $self->result_source;
+ if( $source->has_column($name)
+ && !( $source->has_relationship($name) && ref( $updates->{$name} ) )
+ ){
+ $columns{$name} = $updates->{$name};
+ next;
+ }
+ next if ! $source->has_relationship($name);
+ my $info = $source->relationship_info( $name );
+ if( _master_relation_cond( $source, $info->{cond}, $self->_get_pk_for_related( $name ) ) ){
+ $pre_updates{$name} = $updates->{$name};
+ }
+ else{
+ $post_updates{$name} = $updates->{$name};