From: Peter Rabbitson Date: Wed, 5 Nov 2014 10:49:37 +0000 (+0100) Subject: Correctly document the 'where' attribute X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c704015d816990e1b2f41200ffb13a7f0dce6363;p=dbsrgits%2FDBIx-Class-Historic.git Correctly document the 'where' attribute The documentation was correct when it was written 8 years ago in 4209f49a, but then promptly broken 2 months later by 78060df8 (ironically one of the corner stones of omnipotent chaining) Fix documentation and add an extra test endorsing the current additive behavior. --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 4513011..cf1298e 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -4591,19 +4591,14 @@ setting is ignored and an appropriate warning is issued. =head2 where -=over 4 - -Adds to the WHERE clause. +Adds extra conditions to the resultset, combined with the preexisting C +conditions, same as the B argument to the L # only return rows WHERE deleted IS NULL for all searches __PACKAGE__->resultset_attributes({ where => { deleted => undef } }); -Can be overridden by passing C<< { where => undef } >> as an attribute -to a resultset. - -For more complicated where clauses see L. - -=back +Note that the above example is +L. =head2 cache diff --git a/t/46where_attribute.t b/t/46where_attribute.t index a54adb6..f798ace 100644 --- a/t/46where_attribute.t +++ b/t/46where_attribute.t @@ -6,12 +6,13 @@ use lib qw(t/lib); use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 19; - # select from a class with resultset_attributes my $resultset = $schema->resultset('BooksInLibrary'); is($resultset, 3, "select from a class with resultset_attributes okay"); +$resultset = $resultset->search({}, { where => undef }); +is($resultset, 3, "where condition not obliterated"); + # now test out selects through a resultset my $owner = $schema->resultset('Owners')->find({name => "Newton"}); my $programming_perl = $owner->books->find_or_create({ title => "Programming Perl" }); @@ -82,3 +83,5 @@ if ($@) { print $@ } ok( !$@, 'many_to_many set_$rel(\@objects) did not throw'); is($pointy_objects->count, $pointy_count, 'many_to_many set_$rel($hash) count correct'); is($round_objects->count, $round_count, 'many_to_many set_$rel($hash) other rel count correct'); + +done_testing;