Icon_search
Colin

private method `split' called for Symbol

Posted on 08/12/2008 by Colin
0 Comments

Thank God for Lighthouse.

I got this error (private method `split' called for :id:Symbol, in my case) because my has_many statement had :order => :id specified (yes, it looks a trivial order; it's legacy code, so give me a break).

Aha! We shouldn't be using symbols to represent table columns in our has_many statements. We're really talking about an SQL fragment, anyway, so it seems more sensible to use a string anyway. Consider a case where you want to include another table:

class Organization < ActiveRecord::Base
  has_many :users, :order => "accounts.number", :include => :account
end
class User < ActiveRecord::Base
  belongs_to :organization
  belongs_to :account
end
class Account < ActiveRecord::Base
  has_one :user
end

Certainly there's no way to do :accounts.number or something like that, and it doesn't make sense anyway. Long story short, it's OK to use Symbols for table names, but leave the columns to the strings, please!

Tagged:  private method symbol errors rails

Comments

Be the first to add a comment.

Post a Comment

Name

Comment

simple_captcha.jpg
Please type the letters from the image.