2011-04-26 45 views
0

進出口新的軌道如何加入這張表?

錯誤

Mysql2::Error: Unknown column 'states.ad_id' in 'where clause': SELECT `states`.* FROM `states` WHERE (`states`.ad_id = 1) LIMIT 1 

我的模型

ad.rb

has_one :state 

state.rb

belongs_to :ad 

這裏是我的表格。

廣告

+----+----------------+-------------+-------+-----------+ 
| id | title   | description | price | states_id | 
+----+----------------+-------------+-------+-----------+ 
| 1 | ebook   | asdasd  |  1 |   1 | 
| 2 | iphone 4 devol | sdfsdf  |  1 |   1 | 
| 3 | asd   | asd   |  1 |   2 | 
+----+----------------+-------------+-------+-----------+ 

狀態

+----+----------+ 
| id | name  | 
+----+----------+ 
| 1 | Pluto | 
| 2 | Mars  | 
+----+----------+ 

回答

1

你的錯誤信息告訴你,你沒有在狀態表ad_id列。 您可能想使用states.id而不是states.ad_id