Re: [CDBI] Best way to do this

[prev] [thread] [next] [Date index for 2005/09/10]

From: William Ross
Subject: Re: [CDBI] Best way to do this
Date: 13:48 on 10 Sep 2005
On 10 Sep 2005, at 04:27, Kate Yoak wrote:

> I am attempting to do something that ought to be easy, but I can't  
> quite
> figure out the best approach.
>
> BOB->has_many('friends'...);
>
> But I'd like to put a little custom logic into BOB->friend, such as:
>
> sub friends{
>  my $self = shift;
>  my $friends = $self->SUPER::friends(@_);
>  if (@friends ==1 && !wantarray){
>     return shift @friends;
>  }
>  ...
> }
>
> Of course HasMany complains about already having friends defined.   
> I can
> certainly work around this, and I might anyway - but what's a good  
> way to
> solve the general case of doing some post-processing on the data?


BOB->has_many( _friends => ... );

sub friends {
     my $self = shift;
     my $friends = $self->_friends;
     ...
}

note that $friends here will be an iterator.

The other likely alternative is to write a custom retrieval method  
and skip the relationship definition, especially if more fancy SQL is  
required.

best

will


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

[CDBI] Best way to do this
Kate Yoak 03:27 on 10 Sep 2005

Re: [CDBI] Best way to do this
William Ross 13:48 on 10 Sep 2005

Generated at 23:46 on 13 Sep 2005 by mariachi v0.52