Grid search with the Model services

November 21, 2017 2:17pm

Subscribe [2]
  • #1 / Nov 21, 2017 2:17pm


    79 posts

    Is it possible to search with the Model service in grid data.


    $query = ee('Model')->get('ChannelEntry');
    $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 (

    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;
  • #2 / Nov 21, 2017 2:32pm

    Seth Barber's avatar

    Seth Barber

    172 posts

    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();
  • #3 / Nov 21, 2017 2:36pm


    79 posts


.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases