Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying a model by a many_many relationship with Silverstripe DataModel

Tags:

silverstripe

If i have a Model DebatePage which has the following many many relationship:

 private static $many_many = array(
    'Panelists'     => 'Panelist'
  );

and the panelist has a text field called "Name"

How can i query for all the debates that have a panelist called bob?

DebatePage::get()->filter('Panelist.Name:partialmatch', $keyword);

but i get an unknown column error

like image 642
Will Avatar asked Feb 15 '23 06:02

Will


1 Answers

I was nearly there

DebatePage::get()->filter('Panelists.Name:partialmatch', $keyword);

So I just needed to use the relationship name, not singularised. Amazing how good SS data model is.

like image 184
Will Avatar answered Apr 28 '23 04:04

Will