Re: WHERE-clause filtering for dynamic anonymous views

[prev] [thread] [next] [Date index for 2004/07/16]

From: colm-cdbi
Subject: Re: WHERE-clause filtering for dynamic anonymous views
Date: 14:16 on 16 Jul 2004
On Fri, Jul 16, 2004 at 10:36:28AM +0100, Simon Cozens wrote:
> I haven't done anything about this, and I'm just floating the idea to see if
> it's sane, (and to make sure I don't forget it) but...
> 
> I think it might be useful to have a plug-in which remembers additional
> WHERE clauses to tag onto a request, to narrow down the scope of any searching
> or updates.
> 
> For instance, suppose instead of a CD table, you have a Music table which
> a "format" field - some records have format "CD", some have "12inch", and
> so on. Then:
> 
>     my $cds = Music->filter(format => "CD");
> 
> Now you can use $cds like a Class::DBI::Pager object:
> 
>     $cds->retrieve_all;
> 
> will return you all the items with format of "CD".
> 
> I don't know if this will be feasible to implement with the current design of
> Class::DBI, or whether it would be a good idea, but I can think of some uses
> for it. (For instance, I know Jesse has tables with a "deleted" column that it
> would be good to filter on.)

I hope I'm not missing the point but perhaps this could be implented in a
similar way to how Apache::Registry works i.e. it could generate an on-the-fly
subclass of Music with class data to represent the filter, e.g. :

  package Music::Filter::format__cd_some_clever_naming_convention;

  use base ('Music');
  __PACKAGE__->filter_data('format' => 'CD');

If filter_data were hooked into search(), retrieve_all() then you could
use the lot, e.g. :

  # $cds_from_1994 gets set to 
  #   'Music::Filter::format__cd_some_clever_naming_convention'
  my $cds_from_1994 = Music->filter('format' => 'CD', 'year' => 1994);

  my @all_from_1994 = $cds_from_1994->retrieve_all;
  my @all_by_Blur_in_1994 = $cds_from_1994->search('Artist' => 'Blur');

  # this could check to ensure the 'id' matches the criteria 
  # of the filter and if not then return undef
  my $cd = $cds_from_1994->retrieve(14);

  # this would have the filter data assumed
  my $cd = $cds_from_1994->create({
             title => 'The Great Escape',
	     artist => 'Blur',
           });

#--

Does this make any sense at all or have I taken a good idea and ruined it?

Perhaps filter_data would be a useful concept at any rate - or does
something like this already exist that I don't know about - or is it
just OO hesesy?

Colm

Re: WHERE-clause filtering for dynamic anonymous views
colm-cdbi 14:16 on 16 Jul 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52