sql基础一定要学好

遇到这样的一个问题.看代码
在work_sheet的model中
  named_scope :working ,:conditions => ["qted = ? and start > ? ",4,DateTime.now]
  named_scope :starting,:conditions => "production_plans.state = 0", :include => :production_plan

#不报错
WorkSheet.working
#不报错
WorkSheet.starting
#报错
WorkSheet.starting.working

不明白为什么会这样?报错如下:
Mysql::Error: Column 'start' in where clause is ambiguous: SELECT `work_sheets`.* FROM `work_sheets` INNER JOIN `production_plans` ON `production_plans`.id = `work_sheets`.production_plan_id WHERE ((production_plans.state = 0) AND (qted = 4 and start > '2010-04-09 14:14:50' ))

sql跑了下也是报错,没有仔细研究,就拿去请教别人去了.ambiguous原来是模棱两可的意思.在worksheet和production_plan里都有start字段,然后关联后,就无法确认是哪个的start字段了.自己再改成这样,然后试了下.可以了.
named_scope :working ,:conditions => ["qted = ? and work_sheets.start > ? ",4,DateTime.now]

你可能感兴趣的:(sql,mysql,Ruby,UP)