[CDBI] Retrieve only one result from a has_many

Matt Adams matt.adams at morcor.com
Fri Dec 16 22:36:14 GMT 2005


Hello fellow CDBI users:

I have an interesting situation concerning the use of a has_many 
relationship.

I have two tables.  For the sake of simplicity let's assume that they 
are called "version" and "deadline" where there can be many deadlines 
for any given version.

I have the following CDBI relationships set up like this:

MyApp::DB::Deadline->has_a( versioncode => 'MyApp::DB::Version' );
MyApp::DB::Version->has_many( deadlines => 'MyApp::DB::Deadline' );

Now, when I retrieve a particular version via

$object = $MyApp::DB::Version->retrieve( 23 );

I get back a bunch of nifty looking objects with blessed references to 
the related deadlines (which is cool if I need to iterate over a number 
of deadlines and whatnot).

Here is my problem:

I have a situation where I must retrieve one particular deadline for a 
specific version and even though I have a has_many relationship here I 
only want to get the value of the specific deadline according to a 
column value in MyApp::DB::Deadline (say the column is something like 
deadline.dset).

So, when I retrieve a version like the $class->retrieve() above I don't 
want a blessed reference to ALL of the related deadlines; I only want to 
get back a blessed reference (or perhaps not a reference at all but a 
value) of the related deadlines with the deadline.dset value of 5.

Is there a simple way to go about this?

Any suggestions or comments would be greatly appreciated.


Thank you,

Matt




More information about the ClassDBI mailing list