Skip to content

do I need to modify this to use it with jenssegers/laravel-mongodb ? #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vesper8 opened this issue Jan 16, 2018 · 5 comments
Closed

Comments

@vesper8
Copy link
Contributor

vesper8 commented Jan 16, 2018

I am using jenssegers/laravel-mongodb and using hybrid relations between mysql models and mongodb models

the mongodb models however rather than extend laravel's default model, extend a special wrapper model of sorts

a lot of model-related packages on github do work out of the box with mongodb models but I'm not sure how to use this one since it depends on extending a different model

any chance you could have a quick look at jenssegers/laravel-mongodb and see if there's a quick and easy solution to using it with your package?

thanks much!

@vesper8
Copy link
Contributor Author

vesper8 commented Jan 16, 2018

I've gone ahead and made a duplicate of your CachedModel and called ot MongoCachedModel,

Then inside that class I replaced the extend Model by extend Eloquent

And added use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

That's all that was needed to get it to work with mongodb models

Except that now I can't use the artisan flush command on that model because it's not an instance of "CachedModel"

Can you think of a more elegant way to handle this?

@vesper8
Copy link
Contributor Author

vesper8 commented Jan 16, 2018

I also ran into one problem so far when working with mongodb models. Unlike with mysql, sometimes the values are arrays themselves and that triggered a Array to String conversion error on these lines inside the CacheKey

        $value = array_get($where, 'value');
        $value .= $this->getTypeClause($where);
        $value .= $this->getValuesClause($where);

I was able to fix it by changing it to

        $value = array_get($where, 'value');
        if (is_array($value)) {
            $value = implode("_", $value);
        }
        $value .= $this->getTypeClause($where);
        $value .= $this->getValuesClause($where);

@mikebronner
Copy link
Owner

Interesting, I will see about adding this. If you can submit a PR that would expedite things, but it sounds like a good idea.

@vesper8
Copy link
Contributor Author

vesper8 commented Jan 17, 2018

Update: Doh.. I had totally forgot I had done another small change on my dev only.. inside the vendor files.. ugh.. and hadn't pushed it to my fork.. It was this change in the Cachable trait:

            //if (is_a($this, CachedModel::class)) {
                array_push($tags, str_slug(get_called_class()));
            //}

hey @mikebronner I'm hoping maybe you can think of something here...

what I mentioned above is really the only small change I needed to do in order to get it to work with my mongodb models. This was working perfectly on my DEV environment. Mongo models were being invalidated exactly as you'd expect a mysql model to.. no biggie

but then tonight I deployed my changes to production.. and I'm baffled.

Mysql models are being invalidated, but not the mongo ones! And there are no errors being thrown at all.

I verified that I'm loading my fork correctly with that small change you see above. I cleared all caches.. opcache.. everything.. multiple times. I added \Log::debug in my _CachedMongoModel file which is a clone of CachedModel as I mentioned above. I added logging on the update/saved events and can confirm that it's going in there.. and it's executing the $instance->flushCache();.. and it's not throwing any errors but it won't flush the darn mongo models

I even connected through Medis.. a pretty cool Redis GUI client, and I compared the tag names on both my DEV and production.. and the tag names are the same. If I use the command line to flush models.. it works on DEV for both mysql and mongo tags.. but on Live it only works on mysql models

I made myself my own flush command btw because yours requires that the model be an instance of CachedModel so I just commented those out.

my .env file is almost the same on dev and live.. redis is used for all the drivers.. I really don't think this is an environment issue.. but maybe some obscure difference.. I just spent an hour trying to debug this before I had to revert

Anyway I am really out of ideas of why it isn't able to flush the mongo models on live.. the tags look identical.. ??

if you have any idea you'd really be helping me out here!

Thanks!

@mikebronner mikebronner added this to the 0.3.0 milestone Feb 13, 2018
mikebronner added a commit that referenced this issue Feb 19, 2018
(instead of looking if method exists)
Fixes #81 #57
@mikebronner
Copy link
Owner

Fixed in version 0.2.30. Please re-open if still a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants