-
-
Notifications
You must be signed in to change notification settings - Fork 502
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/where through association isn't using translation table #303
Comments
Oh, interesting. You're using FriendlyId I assume? |
Yes, I have the FriendlyId gem installed, but it works the same way for where-conditions, which aren't altered by FriendlyId as far as I know... @site.pages.where(title: 'my-title').first
|
Yes I know, it's not supported either way at the moment, but I just wanted to check since you mentioned searching by slug. |
Created a branch with a simple failing test to get the ball rolling. |
Great! Good to hear you're on top of it. |
Hmm... this problem is more tricky than expected. I'm trying to avoid monkeypatching ActiveRecord but it's looking to be difficult/impossible. Will keep digging but just wanted to let anyone who is reading this know. |
Wow, it works like a charm with where() trough associations! Even the new find_or_create_by() methods work great. The only thing that doesn't seem to be supported is find() (and the deprecated find_by_* methods). I mention this because the friendly_id-globalize gem uses find() and will still not work properly with this improvement. |
Yes sorry, I realize that and I should be able to fix it. Also I think chaining will not currently work, i.e. The key insight was using the delegated relation classes to patch query methods locally for translated models only. |
Yay, thanks Chris, big joy here on our side! Would like to support your efforts by donating via Gittip, if ok with you? Let me know, if you'd prefer another way alternatively. We're all looking forward to your upcoming commit. |
Thanks that's very kind, but I'm happy to do this for no monetary gain. Handling translated queries on associations is actually really important and something that I'd totally looked over, so glad that you noticed it. |
…r chaining. Fixes chaining issue mentioned in #303.
Ok the chaining issue was easily solved. |
@parndt just to check, is If that's the case, then the issue here should be moved to the issue on that repository. |
FriendlyId doesn't patch |
Yeah that's what I thought. @rvrm can you try testing with the |
Used a global |
Great! I'll clean up the branch a bit and then merge into master. This is a bit experimental so hoping to get some thoughts from @norman before releasing. |
…n for translated model. This enables translated query methods on associations, as discussed in #303.
Using find() or where() directly on my model generates a query which looks up the slug in the page_translations table:
When I use find through a association, the translation table isn't being used. The original table is being used instead.
Adding the scope manually works, but feels more like a hack:
Rails 4.0.1 — Globalize 4.0.0.alpha.2
The text was updated successfully, but these errors were encountered: