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

_typed_columns not working when getting the value

Developer Preview

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

Hi all,

I have a model named cache and save some serialized data to the field ‘result_object’. In the model i set ‘result_object’ as a serialized typed column

protected static $_typed_columns = array(
        'result_object' => 'serialized'
    );

Saving an array result in a serialized string. But getting the data wont unserialize the data.

echo ee('Model')->get('gmaps:Cache')->first()->result_object;

Above code just print a serialized string, instead of an object/array of the data.

Do i miss something, or is this incorrect/correct?

EE version 3.5.4

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
8 years ago
Kevin Cupp's avatar Kevin Cupp

Hmm yes that’s all we do elsewhere in the app, set the column to serialized and then when we access it, it’s an unserialized array. We even have automated tests for this. So, I’m not sure why it wouldn’t be working here. What if you do ->getProperty('result_object')?

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

Hi Kevin,

No luck, same result, just a serialized string.

The model is simple, so i have no idea what it could be…

namespace Gmaps\Model;

use EllisLab\ExpressionEngine\Service\Model\Model;

class Cache extends Model {

    protected static $_primary_key = 'cache_id';
    protected static $_table_name = 'gmaps_cache';

    protected $cache_id;
    protected $address;
    protected $lat;
    protected $lng;
    protected $date;
    protected $search_key;
    protected $geocoder;
    protected $type;
    protected $result_object;

    protected static $_typed_columns = array(
        'result_object' => 'serialized'
    );
}
       
Kevin Cupp's avatar
Kevin Cupp
791 posts
8 years ago
Kevin Cupp's avatar Kevin Cupp

I can’t reproduce this in our Forum module which should be running in the same context as any other add-on. Would you be able to send us this add-on so we can take a closer look? Maybe DM it to me in Slack?

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
8 years ago
Kevin Cupp's avatar Kevin Cupp

For posterity, we found that Reinos was serializing the object before saving, which wasn’t necessary. The models will take care of serializing/unserializing for you.

       

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.