[CDBI] has_many limiting the search.

Praveen Hombaiah phombaiah at gmail.com
Sun Dec 10 04:24:05 GMT 2006


In a given class, while defining a has_many relationship, is it possible to
setup a search criterion,

for instance.
while defining the following relationship, is there a way to limit the CDs
that are returned, lets say we want to return only CDs that are "in_stock".

Music::Artist->has_many(cds => 'Music::CD');


I understand I could do the following while using the Class,

my @cds = $artist->cds(in_stock => 'Y');

but I want this behavior to be default in the class, and not have the
user do this.

Also, I understand, I could use the mapping technique as follows to achieve this
####################

package Music::Artist;
.
.
.
.
Music::Artist->has_many(cds => [ 'Music::CD' => in_stock_only ]);



package Music::CD
..
..
..
sub in_stock_only {
   # return only  cd's that are in stock.
}

####################

but I'm hoping there is a way to just add this search criterion when I'm
setting up the relationship.

Thanks in advance for your help.

-- 
Regards,
Praveen Hombaiah.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digitalcraftsmen.net/pipermail/classdbi/attachments/20061209/c3a1a815/attachment.html


More information about the ClassDBI mailing list