I’m having trouble with one of my Rails model associations. They seem
simple enough, I have 99% of them working. But in one of them, when I
try to access a foreign key record, I get:
undefined method `target’ for #Environment:0xb766c70c
vendor/rails/activerecord/lib/active_record/base.rb:1848:in
method_missing' vendor/rails/activerecord/lib/active_record/associations.rb:891:in
environment’
app/models/revision.rb:154:in start' app/controllers/revisions_controller.rb:9:in
start’
Has anyone seen this? My associations are:
class Revision < ActiveRecord::Base
belongs_to :environment
belongs_to :source_revision,
:class_name => ‘Revision’,
:foreign_key => ‘source_revision_id’
end
class Environment < ActiveRecord::Base
belongs_to :layout
belongs_to :life_cycle
has_many :revisions
has_many :titles, :through => :environment_titles
end
I’ve tried many different variations, singular/plural, etc. BTW, the
‘source_revision’ one works fine (I tried specifying everything to the
environment belongs_to but it didn’t matter)
Here’s my tables, any clues? I’m REALLY stuck…
SQL> desc revisions;
Name Null? Type
ID NOT NULL NUMBER(38)
REVISION NOT NULL NUMBER(38)
ENVIRONMENT_ID NOT NULL NUMBER(38)
REVISION_TYPE_ID NUMBER(38)
EVENT_ID NUMBER(38)
IS_DEPLOYABLE NOT NULL NUMBER(38)
IS_PROMOTABLE NOT NULL NUMBER(38)
SOURCE_REVISION_ID NUMBER(38)
UPDATED_BY VARCHAR2(64)
UPDATED_AT DATE
CREATED_BY VARCHAR2(64)
CREATED_AT DATE
SQL> desc environments;
Name Null? Type
ID NOT NULL NUMBER(38)
ENVIRONMENT NOT NULL VARCHAR2(64)
ENVIRONMENT_DESC VARCHAR2(256)
LAYOUT_ID NOT NULL NUMBER(38)
LIFE_CYCLE_ID NOT NULL NUMBER(38)
UNIX_GID NUMBER(38)
UNIX_UID NUMBER(38)
DEFAULT_DB_SERVER_ID NUMBER(38)
AUTH_OBJECT_ID NOT NULL NUMBER(38)
UPDATED_BY VARCHAR2(64)
UPDATED_AT DATE
CREATED_BY VARCHAR2(64)
CREATED_AT DATE