How to setup relationship in this scenario?
Right now i have created methods like this..
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
TestM开发者_运维百科essage.find(:all,:conditions => ["sfl_test_uri = ?",self.test_uri])
end
end
How may i convert it into relationship ?
Try something like:
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
精彩评论