Ruby on rails 如何使对象成为RubyonRails中模型的属性?

Ruby on rails 如何使对象成为RubyonRails中模型的属性?,ruby-on-rails,object,model,properties,schema,Ruby On Rails,Object,Model,Properties,Schema,我的模式中有以下内容: create_table "robots_matches", :force => true do |t| t.integer "robot_id" t.integer "match_id" 我想我希望能够加载一个机器人并从我的机器人匹配模型中进行匹配,这样我就可以这样做: robots\u match.find(:id).get\u robot().Name 我在robots_matches模型中的尝试是: def get_robot Robot.find(t

我的模式中有以下内容:

create_table "robots_matches", :force => true do |t|
t.integer  "robot_id"
t.integer  "match_id"
我想我希望能够加载一个机器人并从我的机器人匹配模型中进行匹配,这样我就可以这样做: robots\u match.find(:id).get\u robot().Name

我在robots_matches模型中的尝试是:

def get_robot
Robot.find(this.id)
end

我是Rails的超级新手,所以可以自由地修改我的架构决定。

< P>我会考虑下面的模型。 通过“
链接器”
”,允许一个匹配有多个机器人,也允许一个机器人有多个匹配。
然后,您可以执行类似于
Robot.find(1.matches)或
Match.find(1.robots)的查询

class Robot < ActiveRecord::Base
  has_many linkers
  has_many matches, :through => linkers

class Linker < ActiveRecord::Base
  belongs_to :robots
  belongs_to :matches

class Match < ActiveRecord::Base
  has_many linkers
  has_many robots, :through => linkers
classrobot链接器
类链接器链接器

我想从下面的模型开始。 通过“
链接器”
”,允许一个匹配有多个机器人,也允许一个机器人有多个匹配。
然后,您可以执行类似于
Robot.find(1.matches)或
Match.find(1.robots)的查询

class Robot < ActiveRecord::Base
  has_many linkers
  has_many matches, :through => linkers

class Linker < ActiveRecord::Base
  belongs_to :robots
  belongs_to :matches

class Match < ActiveRecord::Base
  has_many linkers
  has_many robots, :through => linkers
classrobot链接器
类链接器链接器

请出示您的模型。请出示您的模型。