| 1 | # $Id$ | ||
| 2 | |||
| 3 | package Data::ObjectDriver::BaseView; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | use base qw( Data::ObjectDriver::BaseObject ); | ||
| 8 | |||
| 9 | use Carp (); | ||
| 10 | use Storable; | ||
| 11 | |||
| 12 | sub search { | ||
| 13 | my $class = shift; | ||
| 14 | my($terms, $args) = @_; | ||
| 15 | $args->{sql_statement} = $class->base_statement($terms, $args); | ||
| 16 | $args = Storable::dclone($args); | ||
| 17 | |||
| 18 | # quick hack: don't use HAVING if view class has datasource | ||
| 19 | if (! $class->properties->{datasource}) { | ||
| 20 | my %cols = map { $_ => 1 } @{ $class->properties->{columns} }; | ||
| 21 | my %having; | ||
| 22 | for my $key (keys %$terms) { | ||
| 23 | if ($cols{$key} && ! $args->{sql_statement}->has_where($key)) { | ||
| 24 | # Don't need to delete from $term, because D::OD ignores | ||
| 25 | # it anyway when used as View class | ||
| 26 | $having{$key} = $terms->{$key}; | ||
| 27 | } | ||
| 28 | } | ||
| 29 | $args->{having} = \%having; | ||
| 30 | } | ||
| 31 | |||
| 32 | $class->_proxy('search', $terms, $args) | ||
| 33 | } | ||
| 34 | |||
| 35 | 1; |