doublesecretagency / craft-googlemaps

Google Maps plugin for Craft CMS - Maps in minutes. Powered by the Google Maps API.
https://plugins.doublesecretagency.com/google-maps/
Other
10 stars 9 forks source link

[craft-5] Database exception when using orderBy('distance') #107

Closed d-karstens closed 6 months ago

d-karstens commented 6 months ago

Hi,

I've just tried migrating one of our sites using this plugin to the Craft 5 beta and encountered this error when using .orderBy('distance') in the following query

{% set options = { 'target': entry.address, 'range': 50, 'components': { 'country': 'AUS' } } %}
{% set related = craft.entries.section('parks').slug('not *' ~ entry.slug ~ '*').address(options).orderBy('distance').limit(3).collect() %}

Screenshot 2024-03-07 at 4 14 55 pm

I did see in your documentation that 'distance' isn't a real column in the database, so guessing that's why it's happening, but I'm unsure if there's a different way we should be doing the query in Craft 5

We're on Craft CMS 5.0.0-beta.6, and 5.0.0-beta.1 of your plugin

Thanks for all your work on the plugin! Let me know if you need any more details

gregorydavidjenkins commented 6 months ago

I'm getting the same error when trying exactly the "Seattle" code from the documentation.

lindseydiloreto commented 6 months ago

Thank you both for reporting it! I'll try to take a look and cut a new beta release shortly. 👍

lindseydiloreto commented 6 months ago

Just wanted to give a quick update on this issue...

I did see in your documentation that 'distance' isn't a real column in the database

Prior to Craft 5, the plugin used a few fancy tricks to determine the distance via SQL, so that the distance value could then be retrieved and added to the Address Model. In Craft 5, however, several critical methods were removed or changed, making it difficult or impossible to pull off the same tricks.

I'm currently working on a new approach, with a backup plan in mind in case it doesn't go well. One way or another, I do believe that I'll have this patch pushed out by the end of the week.

d-karstens commented 6 months ago

Thanks for the update, appreciate it!

lindseydiloreto commented 6 months ago

Good news, I believe this is fixed in v5.0.0-beta.2! 🤞

As you're probably already aware, Craft recently ditched the content table, in favor of a JSON content column in the elements_sites table. I was hopeful that this change would have a minimal impact... but I was not so lucky.

Most of the proximity search happens by manipulating the Element Query object. In Craft 5, however, the underlying SQL query changed significantly. It ended up requiring a sizeable refactor of the proximity search functionality.

Let me know if you hit any other snags! 👍