[CDBI] Re: Retrieve only one result from a has_many

[prev] [thread] [next] [Date index for 2005/12/18]

From: Peter Speltz
Subject: [CDBI] Re: Retrieve only one result from a has_many
Date: 19:56 on 18 Dec 2005
On 12/17/05, Matt Adams <matt.adams@xxxxxx.xxx> wrote:


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

> In other words, is it possible to limit the results returned from
> $object->deadlines based on information I supply when I create the CDBI
> relationships?
>

Patches for this have been available for a couple years now. It is in
the CDBI 3.10 at least but not documented. I think it is noted in the
changes file.   Anyway, get the latest CDBI::Relationship::HasMany and
 try :

MyApp::DB::Deadline->has_a( versioncode =3D> 'MyApp::DB::Version' );
 MyApp::DB::Version->has_many( deadlines =3D> 'MyApp::DB::Deadline' , =20
{constraint =3D> { col1 =3D> XXX , col2 =3D> xxx} );

That should do what you want. I use this some when I have 2 distinct
related groupings.  Similarly, I wrote a might_have  module that I
have yet to put on CPAN that allows contraints.  It is MihtHaveWC.  I
use it to specify the FK and have Multi Keys in the might have. =20
Here's how i use it :

__PACKAGE__->might_have_wc( 'billing_address' =3D> 'DB::Address' =3D>
    qw/street city state zip county addr_type/ ,
    { _FK_ =3D> 'owner_id', owner_table =3D> 'customer', category =3D> "Bil=
ling",
      is_active =3D> 1}
);

---
pjs

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

[CDBI] Re: Retrieve only one result from a has_many
Edward J. Sabol 22:59 on 16 Dec 2005

[CDBI] Re: Retrieve only one result from a has_many
Peter Speltz 19:56 on 18 Dec 2005

Generated at 09:31 on 23 Jan 2006 by mariachi v0.52