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

On 23 Sep 2008, at 17:10, Daniel B. wrote:

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

On Tue, Sep 23, 2008 at 11:29 AM, Frederick C. <
[email protected]> wrote:

)


ANDRES RODRIGUEZ E
Electronic Engineer
Software Developer
IT Consultant

US Phone: (305) 853-8356
Primary Mobile: +57-300-2006186
Secondary Mobile: +57-314-7939859

On Sep 23, 10:33 am, “Andres R.” [email protected] wrote:

table == plural
Got it, thanks.

Dan