通过连接函数看不到属性,但在sql中它可以正常工作

时间:2012-08-23 22:34:50

标签: sql ruby-on-rails activerecord

第一个是本机SQL查询,它正常运行但在活动记录上它没有显示任何关于播放器表的信息。尽管我已授予对Batsman和Player模型文件

的访问权限,但Player.name属性不可见
SELECT  
    players.name, batsmen.*  
FROM 
    batsmen 
INNER JOIN 
    players ON players.id = batsmen.player_id 
WHERE 
    league_id = 13

Batsman.joins(:player).where('league_id = ?',13).select('players.name')

以下是模型

 class Batsman < ActiveRecord::Base   attr_accessible :fours,:name, :siz, :ave,:batsmenViaLeagues, :match, :league_id, :bestf, :fifty, :hights, :hundred, :innings, :nout, :player_id, :runs, :sr, :zero  belongs_to :player  has_many :leagues


class Player < ActiveRecord::Base
  attr_accessible :image, :name   end

0 个答案:

没有答案