[CDBI] Re: newbie: how can I put a placeholder on a query of a has_many relationship?
"Victor Churchill" <[email protected]> Thu, 7 Jun 2007 21:52:14 +0100
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
Thanks Ed for such a quick reply! On 07/06/07, Edward J. Sabol <sabol-2oVx0MVsMgiP/[email protected]> wrote: > I don't think you're missing anything. There's no built-in way of doing this. > It sounds like you want a more flexible implementation of has_many limiting: > > http://search.cpan.org/~tmtm/Class-DBI/lib/Class/DBI.pm#Limiting > > You can't really do complex limiting queries with that, however, AFAIK. I'd seen that in the POD and thought "oh I wish it didn't just limit on equality"! > > You have a couple options that I can see: > > 1. You *might* be able to develop your own Class::DBI::Relationship subclass > to implement this. Refer to HasMany.pm in the Class::DBI distribution > and/or Class::DBI::Relationship::HasManyOrdered on CPAN for examples. I'm > not aware of any implementations that do exactly what you want, but I > agree that it would be nice to have this capability. If you go this route > and get it working, please share the Relationship code with us! > > 2. Put the add_constructor() in the QG::Reading class and then add a simple > "wrapper method" in QG::ALM which takes the number of days as an argument > and passes that argument and any relevant object attributes along to the > QG::Reading constructor that you created and then returns the results. I > think this is what almost everyone does. It's usually only a 3-4 lines of > pretty simple code to implement such a method. (1) sounds a little scary, though I could take a look at it. (2) looks like it may be the way to go; I hadn't thought of the possibility of adding home grown methods in the class. Definitely worth a look. I've also seen a couple of refs to C::DBI::Sweet which I have not come across previously and may be worth investigating. Thanks again - will report back when I have some results. > > Hope this helps, > Ed Certainly did. I now feel less stupid than I did previously.