From: Peter Rabbitson Date: Sat, 16 Oct 2010 00:14:03 +0000 (+0200) Subject: De-golf _is_deterministic_value, add more tests for create() with $rs conds X-Git-Tag: v0.08124~37^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=a780a0ff7c99dd9b640f8c29ad0466bd0c907bf3 De-golf _is_deterministic_value, add more tests for create() with $rs conds --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 5be8a14..7d413d7 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2052,11 +2052,13 @@ sub _merge_cond_with_data { my %implied = %{$self->_remove_alias($collapsed_cond, $alias)}; while ( my($col, $value) = each %implied ) { - if (ref($value) eq 'HASH' && keys(%$value) && (keys %$value)[0] eq '=') { + my $vref = ref $value; + if ($vref eq 'HASH' && keys(%$value) && (keys %$value)[0] eq '=') { $new_data{$col} = $value->{'='}; - next; } - $new_data{$col} = $value if $self->_is_deterministic_value($value); + elsif( !$vref or $vref eq 'SCALAR' or blessed($value) ) { + $new_data{$col} = $value; + } } } @@ -2068,20 +2070,6 @@ sub _merge_cond_with_data { return (\%new_data, \@cols_from_relations); } -# _is_deterministic_value -# -# Make an effor to strip non-deterministic values from the condition, -# to make sure new_result chokes less - -sub _is_deterministic_value { - my $self = shift; - my $value = shift; - my $ref_type = ref $value; - return 1 if $ref_type eq '' || $ref_type eq 'SCALAR'; - return 1 if blessed $value; - return 0; -} - # _has_resolved_attr # # determines if the resultset defines at least one diff --git a/t/72pg.t b/t/72pg.t index 67911aa..f9f61c4 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -225,13 +225,23 @@ for my $use_insert_returning ($test_server_supports_insert_returning arrayfield => [5, 6], }); + my $afield_rs = $schema->resultset('ArrayTest')->search({ + arrayfield => \[ '= ?' => [arrayfield => [3, 4]] ], #Todo anything less ugly than this? + }); + my $count; lives_ok { - $count = $schema->resultset('ArrayTest')->search({ - arrayfield => \[ '= ?' => [arrayfield => [3, 4]] ], #Todo anything less ugly than this? - })->count; + $count = $afield_rs->count } 'comparing arrayref to pg array data does not blow up'; is($count, 1, 'comparing arrayref to pg array data gives correct result'); + + TODO: { + local $TODO = 'No introspection of scalarref conditions :('; + my $row = $afield_rs->create({}); + is_deeply ($row->arrayfield, [3,4], 'Array value taken from $rs condition'); + $row->discard_changes; + is_deeply ($row->arrayfield, [3,4], 'Array value made it to storage'); + } } diff --git a/t/bind/bindtype_columns.t b/t/bind/bindtype_columns.t index 0eab861..a6be997 100644 --- a/t/bind/bindtype_columns.t +++ b/t/bind/bindtype_columns.t @@ -10,8 +10,6 @@ my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/} plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test' unless ($dsn && $dbuser); -plan tests => 6; - my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 }); my $dbh = $schema->storage->dbh; @@ -82,6 +80,15 @@ my $new; $schema->txn_rollback; }); } + + # create with blob from $rs + $new = $rs->create({}); + is($new->bytea, $big_long_string, 'Object has bytea value from $rs'); + $new->discard_changes; + is($new->bytea, $big_long_string, 'bytea value made it to db'); } -$dbh->do("DROP TABLE bindtype_test"); +done_testing; + +eval { $dbh->do("DROP TABLE bindtype_test") }; +