1
我一直在試圖使這個查詢工作了幾個小時,但我不能。所以我希望有人能幫忙。查詢找不到列
這裏的錯誤: 的Mysql ::錯誤:未知列在「NETWORK_ID 'where子句':SELECT networks
* FROM networks
WHERE(NETWORK_ID = 1,2)
這裏是我的模型:
class Network < ActiveRecord::Base
belongs_to :customer
has_many :user_network_relations
class Customer < ActiveRecord::Base
has_one :network, :dependent=>:destroy
accepts_nested_attributes_for :network
class UserNetworkRelation < ActiveRecord::Base
belongs_to :network
accepts_nested_attributes_for :network
控制器
@user = User.find(params[:id])
@user_approved = UserNetworkRelation.find(:all,:conditions => ['user_id = ? and status =? ', @user, "approved"])
@networks = Network.find(:all,:conditions => ['network_id = ?',@user_approved])
@user_networks = Customer.find(@networks)
任何幫助是應用程序reciated。提前致謝!
非常感謝!我使用.find是錯的嗎?例如,如果我做了Network.find(:id => @user_approved).all會有效嗎?謝謝! – yellowreign 2012-01-07 22:29:40
這也可以。但正如我上面所說,ActiveRecord 2的'.find'方法已被棄用。您應該使用新的AREL語法。 – 2012-01-07 22:32:48