Re: might_have , has_many request

[prev] [thread] [next] [Date index for 2005/02/28]

From: Peter Speltz
Subject: Re: might_have , has_many request
Date: 23:24 on 28 Feb 2005
Yeah thats it. You're example is better.  That's pretty much what i did but i
remapped the args rather than provide two level hash in has_many declaration.
Mainly cause i already wrote might_have that way and wanted it consistent. 

One thing it doesn't look like you can provide the "foreign_key" ("third")
argument in your patch.  Just one more line of code in remap_args in the if
(ref $fkey eq "HASH") case would do it. 

I guess i'll post my patch:

# diff -ru HasMany.orig.pm HasMany.pm
--- HasMany.orig.pm     2005-02-28 17:08:44.311188528 -0600
+++ HasMany.pm  2005-02-28 17:18:57.367989728 -0600
@@ -1,5 +1,5 @@
 package Class::DBI::Relationship::HasMany;
-
+# pjs -- modifed to add constraints arg
 use strict;
 use warnings;

@@ -21,7 +21,8 @@

        if (ref $f_key eq "HASH") {    # didn't supply f_key, this is really
$args
                $args  = $f_key;
-               $f_key = "";
+               $f_key = delete $args->{_FK_};          #pjs
+               $args  = { constraints => $args };      #pjs
        }

        $f_key ||= do {
@@ -37,6 +38,7 @@
        }

        $args ||= {};
+       $args->{constraints} ||= {}; # pjs
        $args->{mapping}     = \@f_method;
        $args->{foreign_key} = $f_key;
        $args->{order_by} ||= $args->{sort};    # deprecated 0.96
@@ -112,7 +114,8 @@
                my ($f_class, $f_key, $args) =
                        ($meta->foreign_class, $meta->args->{foreign_key},
$meta->args);
                if (ref $self) {    # For $artist->cds
-                       unshift @search_args, ($f_key => $self->id);
+                       unshift @search_args, ($f_key =>
$self->id,%{$args->{constraints}});
+                       # pjs -- added constraints to search args above
                        push @search_args, { order_by => $args->{order_by} }
                                if defined $args->{order_by};
                        return $f_class->search(@search_args);



 

--- Cees Hek <ceeshek@xxxxx.xxx> wrote:

> > On Mon, Feb 28, 2005 at 01:25:36PM -0800, Peter Speltz wrote:
> > > I'd like it if might_have and has_many relationships took constraints.
> I've
> > > patched my copies so i can use them the old way or like this:
> 
> This looks similar to a patch I provided last year that Tony said
> would appear in the next version.  The relevant thread starts here:
> 
> http://groups.kasei.com/mail/arc/cdbi-talk/2004-06/msg00053.html
> 
> And Tony's response is here (threads got messed up somehow)
> 
> http://groups.kasei.com/mail/arc/cdbi-talk/2004-10/msg00219.html
> 
> This doesn't cover the might_have case, only the has_many...
> 
> -- 
> Cees Hek
> 


=====
pjs


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - 250MB free storage. Do more. Manage less. 
http://info.mail.yahoo.com/mail_250

(message missing)

might_have , has_many request
Peter Speltz 21:25 on 28 Feb 2005

Re: might_have , has_many request
Tony Bowden 22:08 on 28 Feb 2005

Re: might_have , has_many request
Peter Speltz 22:42 on 28 Feb 2005

Re: might_have , has_many request
Cees Hek 22:43 on 28 Feb 2005

Re: might_have , has_many request
Peter Speltz 23:24 on 28 Feb 2005

Re: might_have , has_many request
Tony Bowden 09:41 on 01 Mar 2005

Re: might_have , has_many request
Peter Speltz 18:21 on 01 Mar 2005

Re: might_have , has_many request
Tony Bowden 19:05 on 01 Mar 2005

Re: might_have , has_many request
Peter Speltz 19:27 on 01 Mar 2005

Re: might_have , has_many request
Tony Bowden 22:09 on 01 Mar 2005

Re: might_have , has_many request
Peter Speltz 22:51 on 01 Mar 2005

Re: might_have , has_many request
Tony Bowden 23:39 on 01 Mar 2005

Re: might_have , has_many request
Peter Speltz 01:45 on 05 Mar 2005

Generated at 20:12 on 07 Mar 2005 by mariachi v0.52