开发者

How to setup relationship in this scenario?

开发者 https://www.devze.com 2023-02-16 00:11 出处:网络
Right now i have created methods like this.. class TestMessage < ActiveRecord::Base def test Test.find(:first,:conditions => [\"test_uri = ?\",self.sfl_test_uri])

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

精彩评论

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