Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find() through association isn't using translation table #1

Closed
rvrm opened this issue Nov 3, 2013 · 15 comments
Closed

find() through association isn't using translation table #1

rvrm opened this issue Nov 3, 2013 · 15 comments

Comments

@rvrm
Copy link

rvrm commented Nov 3, 2013

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 ...>
@thomasdarde
Copy link

This is "normal" because find is not surcharged in Friendly ID 5. A proxy must be used like this 👍

User.friendly.find(params[:id])

I don't know if it's working on an association ?
I did have the same problem, and a clear exemple of the new way to use friendly_id-globalize would be much appreciated !

@yadoga
Copy link

yadoga commented Nov 4, 2013

Per the new Friendly_id 5 config file, setting
config.use :finders
is said to activate the :finders method on all models.

Unfortunately the OP's problem persists. Finding through an association seems currently not possible with v5.
@parndt to the rescue.

@norman
Copy link
Owner

norman commented Nov 4, 2013

@yadoga Finding through an association is partly broken because of bugs in Rails 4.0 that will be fixed in 4.0.1. You might want to check and see if the issue described in norman/friendly_id#452 is what's affecting you.

@yadoga
Copy link

yadoga commented Nov 4, 2013

Thanks for your reply @norman. I'm afraid I'm using Rails 4.0.1 here on my end and the problem persists. Maybe you meant the "5.0.1" version of Friendly_id instead?

@thomasdarde
Copy link

I believe he meant 5.0.1 wich will depend on 4.0.1

On 4 nov. 2013, at 18:04, yadoga notifications@github.com wrote:

Thanks for your reply @norman. I'm afraid I'm using Rails 4.0.1 here on my end and the problem persists. Maybe you meant the "5.0.1" version of Friendly_id instead?


Reply to this email directly or view it on GitHub.

@yadoga
Copy link

yadoga commented Nov 4, 2013

Norman speaks of Active Record 4.0.1 in the referenced thread above. Curiously it's now out and does not seem to solve the issue. I'd love my friendly_id healthy again. Please please with sugar on top.

@norman
Copy link
Owner

norman commented Nov 4, 2013

Unfortunately I've never used the globalize functionality and for the next several months need to focus on maintaining Haml. I spent about 2 months working on FriendlyId to the exclusion of Haml and now I need to catch up with pending issues and requests over there. @parndt, the primary maintainer of Globalize and its integration with FriendlyId, is busy with work and other high priority open source projects. It would be fantastic if somebody with a little time to spare could give us a hand with this.

@parndt
Copy link
Collaborator

parndt commented Nov 13, 2013

Does Rails 4.0.1 not fix this issue?

@yadoga
Copy link

yadoga commented Nov 14, 2013

Hi Philip, glad to see you around! Unfortunately the error persists with Rails 4.0.1. Just double checked this. Finding a translated title through an association still returns 'RecordNotFound' as described in the first comment.

@parndt
Copy link
Collaborator

parndt commented Nov 14, 2013

Can anybody make a simple reproducing test case that can be added to the library? This makes it a lot easier to fix. The original post assumes I have a @site and Page model already set up.

@yadoga
Copy link

yadoga commented Nov 14, 2013

ok, setting one up.

@yadoga
Copy link

yadoga commented Nov 14, 2013

Test Case here:
https://github.com/rvrm/Testapp

In this case as "User has_many Pages".

@yadoga
Copy link

yadoga commented Nov 14, 2013

Outch, too late a night for me. Setting up a real test case now, not only a test app.

@yadoga
Copy link

yadoga commented Nov 14, 2013

Testing currently gives me other unrelated errors (Gem.source_index, …), so I'm not able to provide a valid test for the moment. Can anybody give a hand here and set one up?

@rvrm
Copy link
Author

rvrm commented Nov 15, 2013

This seems to be general globalize issue. I added it here: globalize/globalize#303

remi pushed a commit to mirego/friendly_id-globalize that referenced this issue Nov 21, 2016
Fix slug generation when single translation exists
@parndt parndt closed this as completed Jan 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants