Perl DBIx::Class::ResultSet distinct values

1.1k views Asked by At

Hi I would like to get unique (distinct) values from database using DBix::Class but can't find how to do it with my current search method:

my $rs = $schema->resultset('DiscreteCalendar')->search(
        {
            holidaytype => 'W',
            branchcode  => $branchcode,
        },
        {
            select => [{ DAYOFWEEK => 'date' }],
            as     => [qw/ weekday /],
            where       => \['date between ? and ?',$today, $endDate ],

        }
    );

Thank you for your kind help!

1

There are 1 answers

1
Tanktalus On BEST ANSWER

You should be able to just add distinct => 1 in your second hash to the search function, e.g.:

my $rs = $schema->resultset('DiscreteCalendar')->search(
    {
        holidaytype => 'W',
        branchcode  => $branchcode,
    },
    {
        distinct => 1,
        select => [{ DAYOFWEEK => 'date' }],
        as     => [qw/ weekday /],
        where       => \['date between ? and ?',$today, $endDate ],

    }
);