I’ve been trying to make this query work for the last couple of hours, but I can’t. So I hope someone can help.
Here’s the error:
Mysql::Error: Unknown column ‘network_id’ in ‘where clause’: SELECT networks.* FROM networks WHERE (network_id = 1,2)
Here are my models:
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
controller
@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)
Any help is appreciated. Thanks in advance!
The error is in this line:
You are explicitly telling ActiveRecord that you want to restrict the column
network_idwhich obviously doesn’t exist. Probably you meant theidcolumn. The correct line could read as follows:or equivalently
Note that in my example, I used the new ActiveModel / AREL syntax of Rails 3. You used the deprecated (but still supported) Syntax of Rails 2. You should switch to the new syntax as it allows you to chain queries which is mightier and much more readable. See the documentation on how to use the new AREL syntax.