Created
August 17, 2011 08:34
-
-
Save ybart/1151097 to your computer and use it in GitHub Desktop.
Wrong Relationship
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> ActiveRecord::Base.logger = Logger.new(STDOUT) | |
> Infrastructure::Radio.first | |
Infrastructure::Radio Load (0.8ms) SELECT "radio_channels".* FROM "radio_channels" LIMIT 1 | |
+----+------------+ | |
| id | ut_id_name | | |
+----+------------+ | |
| 1 | 245 | | |
+----+------------+ | |
> counter = 0; Infrastructure::Radio.first.foo.each {counter += 1}; puts counter | |
Infrastructure::Radio Load (0.4ms) SELECT "radio_channels".* FROM "radio_channels" LIMIT 1 | |
UserTranslation Load (1.0ms) SELECT "user_translations".* FROM "user_translations" | |
=> 76 | |
> Infrastructure::Radio.first.foo.count | |
Infrastructure::Radio Load (0.4ms) SELECT "radio_channels".* FROM "radio_channels" LIMIT 1 | |
UserTranslation Load (0.8ms) SELECT "user_translations".* FROM "user_translations" | |
SQL (0.6ms) SELECT COUNT(*) FROM "user_translations" WHERE ("user_translations".key = 245) | |
=> 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/models/infrastructure/radio.rb | |
module Infrastructure | |
class Radio < ActiveRecord::Base | |
set_table_name 'radio_channels' | |
has_many :foo, primary_key: :ut_id_name, foreign_key: :key, class_name: "UserTranslation" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment