berlindb / core

All of the required core code
MIT License
255 stars 29 forks source link

get_db returns false when running a date query #17

Closed alexstandiford closed 4 years ago

alexstandiford commented 4 years ago

If I run a query without a date query, everything works as-expected. However, if I include a date query, get_db() returns false.

This appears to be because the date query object is a separate type of query, and it expects that it should also have a $db_global variable set.

As a hotfix, I currently have hard-coded this in my Date_Query object, and it appears to be fixing the problem:

    protected $db_global = 'wpdb';

Obviously this isn't ideal, but I'm really not sure how else this can be resolved. Shouldn't the date query object inherit the db global from the query it's running within?

JJJ commented 4 years ago

Perhaps the date query needs to extend the base, or regular query, or otherwise.

You are correct that value should be inherited, set once and then interacted with at that single point.

alexstandiford commented 4 years ago

See, that's the weird part. Date does extend Base. I just tested this again and it worked as-expected. I just wish I could replicate exactly what I was doing to cause this, because I know that this happened to me at some point.

JJJ commented 4 years ago

I haven't seen this happen yet.

The logic surrounding the WPDB integration is intentionally loose, so my guess is this was just an inheritance/implementation issue.

I think it's OK to close this, and we can reopen if it comes back.