globalize/globalize — pull request #300 by huoxito (2013-11-11 18:18:09+00:00)
Title: Query using Globalize.fallbacks rather than locale only

When fetching a record users might want to grab values from another
locale in case there's no record for the current locale. e.g.

Hey guys noticed that running Globalize 4 alpha doesn't give us the chance to fetch object from database using fallbacks. For example, When searching for a record with the current locale set to `it` I'd expect it to return the record even though the attribute is not found on the current locale.

This is how it used to be back in v0.3.1:

```ruby
[9] pry(Spree):1> Product.find_by_permalink("spree-mug")
Spree::Product::Translation Load (0.7ms) SELECT DISTINCT locale FROM "spree_product_translations" ORDER BY locale
SQL (3.1ms) SELECT DISTINCT "spree_products".id FROM "spree_products" LEFT OUTER JOIN "spree_product_translations" ON "spree_product_translations"."spree_product_id" = "spree_products"."id" WHERE "spree_products"."deleted_at" IS NULL AND "spree_product_translations"."permalink" = 'spree-mug' AND "spree_product_translations"."locale" IN ('it', 'en') AND (spree_product_translations.name IS NOT NULL) AND (spree_product_translations.permalink IS NOT NULL) LIMIT 1
```

This is how it is in current master:

```ruby
[4] pry(Spree):1> Product.find_by(permalink: "spree-mug")
SQL (0.9ms) SELECT DISTINCT "spree_products".id FROM "spree_products" LEFT OUTER JOIN "spree_product_translations" ON "spree_product_translations"."spree_product_id" = "spree_products"."id" WHERE "spree_product_translations"."permalink" = 'spree-mug' AND "spree_product_translations"."locale" = 'it' AND ("spree_products".deleted_at IS NULL) AND (spree_product_translations.name IS NOT NULL) AND (spree_product_translations.permalink IS NOT NULL) LIMIT 1
```

So globalize no longer queries taking into account fallback locales. Now it JOINS only using the current locale (`AND "spree_product_translations"."locale" = 'it'`) instead of `"spree_product_translations"."locale" IN ('it', 'en')`. Is this intended behaviour? I find it awesome the possibility to use fallbacks querying data because we don't want to display empty pages for users in a store. In that case makes a lot of sense to use fallbacks.

please let me know if that makes sense to you? I'd like to write a spec for it but I'll need more time and help to figure it out. Can you see this change bringing trouble?