Search code examples
ruby-on-railsassociationstranslationfriendly-idglobalize3

Friendly_id-globalize 'find() through' association isn't using translation table


In Rails 4: Using find() directly on my model generates a query which looks up the slug in the page_translations table:

Page.find('my-title')
SELECT FROM "pages" LEFT OUTER JOIN "page_translations" ...
-> #<Page id: 1 ...>

When I use find through a association, the translation table isn't being used. friendly_id uses the orginal table instead.

@site.pages.find('my-title')
SELECT "pages".* FROM "pages" WHERE "pages"."site_id" = $1 AND "pages"."slug" = 'my-title' LIMIT 1  [["site_id", 1]]
-> ActiveRecord::RecordNotFound

In Rails 3.2 (friendly_id 4.0.10, globalize 3.0.0) it works like this:

@site.pages.find('my-title')
SELECT "pages".* FROM "pages" WHERE "pages"."shop_id" = 1 AND "pages"."slug" = 'my-title' LIMIT 1
SELECT DISTINCT "pages".id, pages.position AS alias_0 FROM "pages" LEFT OUTER JOIN "page_translations" ...
SELECT "pages"."id" AS t0_r0, "pages"."title" AS t0_r1 ... FROM "pages" LEFT OUTER JOIN "page_translations"
-> #<Page id: 1 ...>

See also https://github.com/norman/friendly_id-globalize/issues/1. Repo owner @parndt is currently busy. So any hints to get this gem working will be greatly appreciated.


Solution

  • Turned out to be a bug in the Globalize gem, which has been fixed shortly.