现在我已经创建了这样的方法..
class TestMessage < ActiveRecord::Base
def test
Test.find(:first,:conditions => ["test_uri = ?",self.sfl_test_uri])
end
end
class Test < ActiveRecord::Base
def test_messages
TestMessage.find(:all,:conditions => ["sfl_test_uri = ?",self.test_uri])
end
end
我如何将其转化为关系?
答案 0 :(得分:2)
尝试类似:
class TestMessage < ActiveRecord::Base
belongs_to :test, :foreign_key => :sfl_test_uri, :primary_key => :test_uri
end
class Test < ActiveRecord::Base
has_many :test_messages, :foreign_key => :sfl_test_uri, :primary_key => :test_uri
end