We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Grid search with the Model services

Developer Preview

Reinos's avatar
Reinos
79 posts
7 years ago
Reinos's avatar Reinos

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}
}
       
Seth Barber's avatar
Seth Barber
172 posts
7 years ago
Seth Barber's avatar Seth Barber

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();
       
Reinos's avatar
Reinos
79 posts
7 years ago
Reinos's avatar Reinos

Thanks!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.