Is it possible to search with the Model service in grid data.
e.g.
$query = ee('Model')->get('ChannelEntry');
$query->with('Grid_field_10');
$query->filter('col_10', 'test');
I did som sort of “nasty” trick to create dynamic models based on the tables, but it fails because is need to create an inverse relation in my addon.file (https://docs.expressionengine.com/latest/development/services/building_models/relationships.html#inverse-relationships)
I use this template for the grid table
namespace Webservice\Model;
use EllisLab\ExpressionEngine\Service\Model\Model;
class Grid_{field_id} extends Model {
protected static $_primary_key = 'row_id';
protected static $_table_name = 'channel_grid_field_{field_id}';
protected static $_relationships = array(
'Entry' => array(
'type' => 'BelongsTo',
'model' => 'ee:ChannelEntry',
'weak' => true
),
);
protected $row_id;
protected $entry_id;
protected $row_order;
{fields}
}
We still have some work to do to make Grid (and Relationship) data available via Models. For the time being the best course of action would be to manually query the grid data tables and retrieve the entry_id
column, then feed those (as an array if more than one) into the Model query for the ChannelEntry: i.e.
ee('Model')->get('ChannelEntry', $entry_ids)->all();
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.