Good afternoon,

On 1/01/10 at 10:32 PM -0600, Pavel O. Karoukin <[email protected]> wrote:

in table "things" i am storing values for each "thing" and it's "type". What
I want to achieve - select all "thing"s which has different type from
current one:

my $things = $schema->resultset("Thing")->first()->different_things();

I am trying to define this as relationship, but from code seems like $cond
in has_many() can accept only foreign and self fieldnames and that's all. No
conditions. It's possible to set conditions in %attr, but this is something
different.

I'm sure someone else can answer this more accurately, but maybe a quick pointer will help here. Rather than creating a relationship, create a method. Eg:

sub different_things {
    my $self = shift;
    my $type = shift || $self->type;
    # other_things is a relationship defined in this package
    return $self->other_things->search({type=>$type}, {order_by=>'sort_idx'});
}



Charlie

--
   Ꮚ Charlie Garrison ♊ <[email protected]>
   〠 PO Box 141, Windsor, NSW 2756, Australia

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
http://www.ietf.org/rfc/rfc1855.txt

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to