This project is archived and is in readonly mode.
Associations.rb throws exception
-
Tarmo Tänav
- State changed from new to incomplete
Symbols working where strings are expected is indeed a difficult issue, in this case to me it seems the problem could instead be solved by converting :join_table to a string right when the association is being defined and that only if it is a Symbol, otherwise we risk accepting invalid values that can be successfully converted to a string (same problem with adding to_s to aliased_table_name_for).
Please do look into writing a patch (with a test) for it.
-
josh
- No changes were found…
-
Ryan Bigg
Is this still an issue? The method does not convert the passed-in name to a string, perhaps it should.
-
Jeroen
- Importance changed from to
I just ran against this one too. If you pass in a symbol as join table, there is an exception thrown: undefined method
downcase' for :products_languages:SymbolBasically if you change
def aliased_table_name_for(name, suffix = nil) if !parent.table_joins.blank? && parent.table_joins.to_s.downcase =~ %r{join(\s+\w+)?\s+#{name.downcase}\sonto
def aliased_table_name_for(name, suffix = nil) if !parent.table_joins.blank? && parent.table_joins.to_s.downcase =~ %r{join(\s+\w+)?\s+#{name.to_s.downcase}\sonit did the trick for me. (notice the .to_s between name and downcase)
I did not have time yet to look more deeply into this, neither to write a patch and/or tests.
-
Neeraj Singh
This is from ActiveRecord test cases.
class Comment < ActiveRecord::Base scope :limit_by, lambda {|l| limit(l) } scope :containing_the_letter_e, :conditions => "comments.body LIKE '%e%'" scope :for_first_post, :conditions => { :post_id => 1 } scope :for_first_author, :joins => :post, :conditions => { "posts.author_id" => 1 } end Comment.for_first_post.for_first_author.allNotice that :joins is accepting table name as symbol. And this test passes successfully.
@Jeroen : Can you provide more information about your model and query so that I could create a failing test case.
thanks
-
Jeroen
Hi Neeraj, below you can find the two models:
class Product < ActiveRecord::Base set_primary_key :products_id has_and_belongs_to_many :languages, :join_table => :products_to_languages, :foreign_key => :products_id, :association_foreign_key => :products_languages_id, :conditions => {:languagenav_id => DVDPost.product_languages[I18n.locale.to_s]} end class Language < ActiveRecord::Base set_table_name :products_languages set_primary_key :languages_id has_and_belongs_to_many :products, :join_table => :products_to_languages, :foreign_key => :products_languages_id, :association_foreign_key => :products_id endIt happens when you do a habtm with a custom join table. These models are mapped to a (nasty) legacy db.
Once I would change the join tables to a string instead of a symbol my problem was fixed. As you can see in my previous post I tracked down the exeption and it’s basicallydowncasethat gets called on a symbol which doesn’t exist.It happens on here
It seems that this issue has been resolved in Rails 3. At least this code has been refactored.
-
Neeraj Singh
- State changed from incomplete to open
- Tag set to activerecord
- Milestone changed from 3.x to 2.3.9
- Importance changed from to Low
-
Jeroen
- Tag cleared.
Okay, this is odd. I've been trying for more than half an hour to reproduce it but I'm not able to do so anymore.
I'll report back if I ever encounter it again.
-
Rohit Arondekar
- State changed from open to invalid
Jeroen, feel free to leave a comment or a patch if you encounter the issue again. Closing for now.
-
Jeff Kreeftmeijer
Automatic cleanup of spam.