-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
undefined method `translations' for nil:NilClass when using finders #282
Comments
Realm.where(name: 'qq' ) -> OK |
This is not documented yet, but the dynamic finders have been deprecated in Rails 4 so we've taken them out of globalize 4.0.0. However in their place we've added functionality to activerecord relations to handle translations, so If you can provide more details (a failing test would be great), I should be able to track down the source. I think I know roughly where the problem is. |
Can you try the branch I just pushed? Change gem 'globalize', github: 'globalize/globalize', branch: '282_finders_nil' |
changing to newer gem gem 'globalize', github: 'globalize/globalize', branch: '282_finders_nil' solves both issues as for dynamic finders - i understand that they deprecated names like find_by_name, but not find_by name: Anyway, it works now for both cases... |
great! I'll merge the change into master a bit later on. Also, |
merged into master, so I'm closing this. |
This fixed the issue for me too, hooray! |
When trying to use finders as find_by or find_by_name globalize fires exception in case when the record not found, for example:
Realm.create name: 'aa'
-> created an instance OK
Realm.find_by_name 'aa' -> OK
SQL (0.2ms) SELECT DISTINCT
realms
.id FROMrealms
LEFT OUTER JOINrealm_translations
ONrealm_translations
.realm_id
=realms
.id
WHERErealm_translations
.name
= 'aa' ANDrealm_translations
.locale
= 'ru' AND (realm_translations.name IS NOT NULL) LIMIT 1SQL (0.1ms) SELECT
realms
.id
AS t0_r0,realms
.name
AS t0_r1,realms
.default_locale
AS t0_r2,realms
.default_time_zone
AS t0_r3,realms
.created_at
AS t0_r4,realms
.updated_at
AS t0_r5,realm_translations
.id
AS t1_r0,realm_translations
.realm_id
AS t1_r1,realm_translations
.locale
AS t1_r2,realm_translations
.created_at
AS t1_r3,realm_translations
.updated_at
AS t1_r4,realm_translations
.name
AS t1_r5 FROMrealms
LEFT OUTER JOINrealm_translations
ONrealm_translations
.realm_id
=realms
.id
WHERErealm_translations
.name
= 'aa' ANDrealm_translations
.locale
= 'ru' ANDrealms
.id
IN (1) AND (realm_translations.name IS NOT NULL)Realm::Translation Load (0.2ms) SELECT
realm_translations
.* FROMrealm_translations
WHERErealm_translations
.realm_id
= 1<Realm id: 1, name: "aa", default_locale: "RU", default_time_zone: "aa", created_at: "2013-10-21 10:31:50", updated_at: "2013-10-21 10:31:50">
When using
Realm.where name: 'qq'
Realm.where(name: 'qq' ) -> OK
Realm.where(name: 'qq' ).first -> error
NoMethodError: undefined method `translations' for nil:NilClass
The text was updated successfully, but these errors were encountered: