strange activerecord error
So I’m using the ActiveRecord gem (outside of rails) to translate some data from our old forum database to YAML, so it can be imported into a different system. But I’m getting an error on one of my models that I just can’t figure out. Here are the details:
class Topic < ActiveRecord::Base
set_table_name "forum_topics"
set_primary_key "TOPIC_ID"
has_many :replies, :foreign_key => "TOPIC_ID"
belongs_to :forum, :foreign_key => "FORUM_ID"
belongs_to :member, :foreign_key => "T_AUTHOR"
end
class Reply < ActiveRecord::Base
set_table_name "forum_replies"
set_primary_key "REPLY_ID"
belongs_to :member, :foreign_key => "R_AUTHOR"
belongs_to :topic, :foreign_key => "TOPIC_ID"
belongs_to :forum, :foreign_key => "FORUM_ID"
end
So, we’ve got two models, Topic and Reply (well, there are more, but they aren’t interesting to the discussion here). The associations are as you’d expect, and I’m telling AR about the legacy DB’s schema.
Everything you’d expect to work with Topics does indeed work:
>> Topic.count
=> 828
>> Topic.first.T_SUBJECT
=> "Rave Review"
But Replies are screwy for some reason. The associations all work, but trying to get a field’s value barfs out. Example:
>> Reply.count
=> 2278
>> Reply.first.topic.T_SUBJECT
=> "Rave Review"
>> Reply.first.R_DATE
ArgumentError: wrong number of arguments (1 for 0)
from (irb):374:in `method_missing`
from (irb):374
from :0
>> Reply.first['R_DATE']
=> "20041206085839"
I’m at a loss. Why can’t I get values from Replies? Topics work fine. For the moment, I’m using the Reply.first['R_DATE'] syntax, but I’d rather not. Anyone out there have any ideas?