[Dbix-class] Literals in relationships

Ash Berlin ash at cpan.org
Wed Dec 20 09:17:09 GMT 2006


Christopher Heschong wrote:
> Literals don't seem to work for relationships for me.  For instance:
> 
> my $foo = 'bar';
> __PACKAGE__->has_many(
>     'things',
>     'MyApp::Schema::Thing',
>     {
>         'foreign.key' => 'self.id',
>         'foreign.foo' => \$foo
>     }
> );
> 
> doesn't seem to work.  I'm probably missing something simple, as usual.  
> Any alternate ways of doing this?

Nope - currently you can do it.

The way I do something similar is with a function like:

sub things {
   my ($self, $foo) = @_;

   return $self->things_rs->search_rs({foo => $foo });
}

But with better naming.

-a



More information about the Dbix-class mailing list