【发布时间】:2010-05-04 20:59:50
【问题描述】:
这是我的模型:
#game
class Game < ActiveRecord::Base
#relationships with the teams for a given game
belongs_to :team_1,:class_name=>"Team",:foreign_key=>"team_1_id"
belongs_to :team_2,:class_name=>"Team",:foreign_key=>"team_2_id"
def self.find_games(name)
items = Game.find(:all,:include=>[:team_1,:team_2] , :conditions => ["team_1.name = ?", name] )
end
end
#teams
class Team < ActiveRecord::Base
#relationships with games
has_many :games, :foreign_key =>'team_1'
has_many :games, :foreign_key =>'team_2'
end
当我执行 Game.find_games("real") 我得到: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: team_1.name
如何解决我认为使用 :include 可以解决问题的问题。
【问题讨论】:
标签: ruby-on-rails ruby activerecord