On Jun 17, 2010, at 5:55 AM, Dexter Tad-y wrote:
As a wishlist (or more like me rambling here), I'd like to
see a place to
plug in SQL
result-sets directly, say:
package Person;
...
result_set 'underage' => (
sql => "select * from person where
age<18"
);
That way difficult queries (ie: outer joins?) or often-used
queries may be
easily
implemented, and special composite (joint) objects may
exist.
What you are describing sounds like a Repository (http://martinfowler.com/eaaCatalog/repository.html
), or maybe a plain PhraseBook-style object. DataMapper's philosophy
encourages encapsulation of the session (connection). But you can
still write classes with access to the session object so that you
may encapsulate often used queries.
Actually I really like Rodrigos idea and I think perhaps you might be
misunderstanding it because the example is quite simple. So it would
be possible to do what he is asking by doing this (forgive me if the
API is a little off, this is pseudo-DataMapper code :))
package Person;
...
sub underage {
my ($self, $session) = @_;
$session->objects( $self )->filter('age < ?', 18);
}
Then Person->underage($session) would return a resultset of all
underage persons. But what Rodrigo is asking for seems like a special
wrapper for this, perhaps something like this:
resultset 'underage' => (
where => [ 'age < ?', 18 ]
);
So the underage method would still expect a $session arg, but would
automatically generate the code to do that. Then to return to Rodrigos
example, if you had a really insane complex mess of joins and other
SQL insanity to return a set of Person objects, then you could use the
example he provided and $session would simply do the right thing.
Anyway, thats just how I read it, I may be totally wrong :)
- Stevan