Вопрос

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.

Это было полезно?

Решение

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' },
    }
);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top