简体   繁体   中英

ORM Relation Caching

Without unused words, I need some advice.

I'm building another app basing on KohanaPHP 3.0.9 framework, felt in love with ORM (Real productivity booster!).

I got Model_User model:

class Model_User extends ORM
{
    protected $_table_name = 'users';
    protected $_primary_key = 'id';

    protected $_has_many = array(
        'articles' => array(
            'through' => 'users_articles',
        ),
    );

    protected $_ignored_columns = array('articles');
}

I have gone with thin controller/fat model philosophy so the correct place for data is model in my development.

What is $_ignored_columns ? In few places I need to return $user object so I'm returning it with articles (when needed) as $user method: $user->articles->find_all() ;

So far so good, everything is working really perfectly. I'm not quite sure if my approach with $_ignored_columns is correct, if not, please let me know with advice how to solve it.

However, I'm facing an issue with caching. Generally, everything is working correctly expect articles. It just gets ignored by cache (not saved in cache file). I also tried to cache it separately - still without luck.

Any suggestions?

Ignored columns are just some "imaginary" fields you can have in a model, which ORM will not try to save on save() (like password_confirm field in Model_Auth_User)

I don't really see why you would cache articles as it doesn't really make much sense, though you'll have to do it manually (like adding additional get_articles() method which will check if there's cache for currently loaded article and return it), but you'll be just getting yourself a headache for no particular reason (how slow the query really is, it's a select by primary key through a pivot table?).

ORM doesn't support any caching by default (except for table columns).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM