statamic / eloquent-driver

Provides support for storing your Statamic data in a database, rather than flat files.
https://statamic.dev/tips/storing-content-in-a-database
MIT License
104 stars 74 forks source link

Querying missing localization data doesn't work #112

Closed jasonvarga closed 1 year ago

jasonvarga commented 1 year ago

On localized entries, any fields that you don't choose to localize will fall back to what's in the origin. That's fine.

However if you try to perform a query on one of these fields, the localized versions will not appear.

For example: (using yaml to represent the rows, obviously in eloquent it's stored differently)

id: 1
title: Origin entry
foo: bar
id: 2
origin_id: 1
title: Localized entry
# foo is intentionally missing, because we want it to fall back to bar
Entry::query()->where('foo', 'bar')->get(); // only returns the origin entry

In the Stache driver it works fine because the indexes/columns are generated on the fly.

An idea: store all the data so it's queryable, but also store something like localized_keys so we can work out what goes in $entry->data() when we build the objects.

ryanmitchell commented 1 year ago

That would work but it would mean we also need to re-save any localisations when the origin is saved so the new values propagate.

The only other option I can think of is updating the query builder to also look for values on the parent (using ->whereHas() or something similar). But that would get messy.

jasonvarga commented 1 year ago

I'd be fine with saving dependents.