Association error using find since upgrading to Rails 2.1.1

Hi all,

Ruby 1.8.6 Rails 2.1.1

I have a simple association that works fine under 1.2.6 but is failing under 2.1.1.

require 'active_record'

ActiveRecord::Base.establish_connection(    :adapter => 'postgresql',    :database => 'my_database,    :username => 'postgres' )

class Schedule < ActiveRecord::Base    belongs_to :user end

class User < ActiveRecord::Base    has_many :schedules end

# This works with AR 2.1.1 s = Schedule.find(:first) p s.user_id p s.user.cuid

# This does not with AR 2.1.1 => PGError: ERROR: column "cuid" does not exist s = Schedule.find(    :first,    :include => [:user],    :conditions => ["cuid = ?", "foo"] # Also tried user.cuid )

What obvious bit am I missing?

Thanks,

Dan

# This does not with AR 2.1.1 => PGError: ERROR: column "cuid" does not exist s = Schedule.find(   :first,   :include => [:user],   :conditions => ["cuid = ?", "foo"] # Also tried user.cuid )

What obvious bit am I missing?

You need to qualify that column name (ie users.cuid)

Fred

When you make a find with ‘include’ you are using two tables in a SQL query, so you need to explicitly write the table_name.row_name when using conditions.

user is not the table, that’s why user.cuid didn’t work. users is the table name.

Remember:

Model == Singular table == plural

Got it, thanks.

Dan