开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜