1

I have a many-to-many relationship for objects in an SQL database in a Dancer server, and I need to be able to search objects based on a criteria on the other. In other words, I need to be able to do what is asked in this question but in Dancer.

The relationship is modeled as described in the Dancer DBIx::Class documentation here.

I see examples of how to search based on one-to-many relationships here but I have not been able to translate this to many-to-many.

Community
  • 1
  • 1
skynet
  • 9,898
  • 5
  • 43
  • 52

1 Answers1

2

If you read the DBIx::Class docs carefully, you'll see that many-to-many is not a relationship but a relationship bridge. You can still filter on related columns by joining the relationships that form the many-to-many:

my $rs = $schema->resultset('Artist')->search({
        'tracks.name' => 'Always',
    },{
        join => { cds => 'tracks' },
    }
);
Alexander Hartmaier
  • 2,178
  • 12
  • 21