Re: search() without search criteria

[prev] [thread] [next] [Date index for 2005/04/29]

From: Tony Bowden
Subject: Re: search() without search criteria
Date: 22:48 on 29 Apr 2005
On Fri, Apr 29, 2005 at 09:19:32PM +0100, Will Hawes wrote:
> If anything, CDBI has an illogical approach to retrieving data because
> it uses three separate methods, search(), retrieve() and retrieve_all(),
> to do the job of SQL's SELECT statement.

One of the issues in ORM is the mismatch of ideas. This is one of them.
We don't have a select() method. This is deliberate.

> Ultimately "retrieve" and "retrieve_all" are just specific types of search. The former for a specific record in a table, the latter for all records. So these two statements would be the same:
> @cds = CD->retrieve_all({});
> @cds = CD->search({});

retrieve_all() shouldn't take restricting arguments. If you're doing
that then you're not retrieving all records.

search() shouldn't take no arguments, as then you're not doing a search.

> Using the latter method, a "search or browse" function can be made
> simpler. No need to modify your base class to have artificial columns
> and pass artificial stuff like "{1 => 1}" to search(). No need to test
> whether criteria were specified and if not, call to retrieve_all()
> instead. You just pass your user's search criteria directly to search()
> - if no criteria are specified, it just returns all records.

You don't need to have artifical columns and 1 => 1 searches to do that:

	sub My::CDBI::Subclass::search {
		my ($class, @args) = @_;
		return $class->retrieve_all unless @args;
		return $class->SUPER::search(@args);
	}

(Modifying this to cope with the case of no restrictions but with extra
options is left as a fairly simple exercise for the reader)

Tony


(message missing)

search() without search criteria
Will Hawes 12:36 on 29 Apr 2005

Re: search() without search criteria
Matt S Trout 13:18 on 29 Apr 2005

Re: search() without search criteria
Daniel Wijnands 14:06 on 29 Apr 2005

Re: search() without search criteria
Perrin Harkins 14:25 on 29 Apr 2005

Re: search() without search criteria
Will Hawes 16:53 on 29 Apr 2005

Re: search() without search criteria
Tony Bowden 18:38 on 29 Apr 2005

Re: search() without search criteria
Matt S Trout 19:38 on 29 Apr 2005

Re: search() without search criteria
Will Hawes 20:19 on 29 Apr 2005

Re: search() without search criteria
Tony Bowden 22:48 on 29 Apr 2005

Re: search() without search criteria
Perrin Harkins 16:40 on 30 Apr 2005

Re: search() without search criteria
David Baird 14:31 on 29 Apr 2005

Re: search() without search criteria
Peter Speltz 19:11 on 29 Apr 2005

Re: search() without search criteria
Tony Bowden 22:52 on 29 Apr 2005

Re: search() without search criteria
Will Hawes 12:13 on 30 Apr 2005

Re: search() without search criteria
Tony Bowden 12:19 on 30 Apr 2005

Re: search() without search criteria
merlyn (Randal L. Schwartz) 15:44 on 30 Apr 2005

Re: search() without search criteria
Will Hawes 17:45 on 30 Apr 2005

Re: search() without search criteria
Tony Bowden 10:27 on 01 May 2005

Re: search() without search criteria
Will Hawes 14:13 on 01 May 2005

Generated at 10:24 on 04 May 2005 by mariachi v0.52