Daniel Berger
2008-Sep-23 16:10 UTC
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Sep-23 16:29 UTC
Re: Association error using find since upgrading to Rails 2.1.1
On 23 Sep 2008, at 17:10, Daniel Berger wrote:> > # 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> Thanks, > > Dan > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Andres Rodriguez
2008-Sep-23 16:33 UTC
Re: Association error using find since upgrading to Rails 2.1.1
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 Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 23 Sep 2008, at 17:10, Daniel Berger wrote: > > > > # 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 > > Thanks, > > > > Dan > > > > > > > >-- ANDRES RODRIGUEZ E Electronic Engineer Software Developer IT Consultant US Phone: (305) 853-8356 Primary Mobile: +57-300-2006186 Secondary Mobile: +57-314-7939859 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Berger
2008-Sep-23 19:18 UTC
Re: Association error using find since upgrading to Rails 2.1.1
On Sep 23, 10:33 am, "Andres Rodriguez" <andres...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 == pluralGot it, thanks. Dan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---